Repository: sveltejs/kit
Pull request #4152 (2022-02-28 10:38:19)

`undefined` as valid `JSONValue` type
From the first question discussed in #4124, we also need this change to fix (not yet GitHub) #1997

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpx changeset` and following the prompts. All changesets should be `patch` until SvelteKit 1.0


changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: 74363c4bef19026c4c3826966638cfccaf9a14aa

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name          | Type  |
| ------------- | ----- |
| @sveltejs/kit | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/sveltejs/kit/new/undefined-as-valid-json-value-type?filename=.changeset/rotten-laws-train.md&value=---%0A%22%40sveltejs%2Fkit%22%3A%20patch%0A---%0A%0A%60undefined%60%20as%20valid%20%60JSONValue%60%20type%0A)



Patch:
diff --git a/.changeset/purple-readers-build.md b/.changeset/purple-readers-build.md
new file mode 100644
index 000000000..762698421
--- /dev/null
+++ b/.changeset/purple-readers-build.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+`RequestHandlerOutput` accepts body when it has or maybe is `undefined`
diff --git a/documentation/docs/13-configuration.md b/documentation/docs/13-configuration.md
index 54f77a5ef..0bc7ff71b 100644
--- a/documentation/docs/13-configuration.md
+++ b/documentation/docs/13-configuration.md
@@ -132,7 +132,7 @@ export default config;
 
 When pages are prerendered, the CSP header is added via a `<meta http-equiv>` tag (note that in this case, `frame-ancestors`, `report-uri` and `sandbox` directives will be ignored).
 
-> When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbiddem.
+> When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
 
 ### files
 
diff --git a/packages/kit/types/private.d.ts b/packages/kit/types/private.d.ts
index d51d7864e..33b8d487f 100644
--- a/packages/kit/types/private.d.ts
+++ b/packages/kit/types/private.d.ts
@@ -208,7 +208,15 @@ export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
 
 export type JSONObject = { [key: string]: JSONValue };
 
-export type JSONValue = string | number | boolean | null | ToJSON | JSONValue[] | JSONObject;
+export type JSONValue =
+	| string
+	| number
+	| boolean
+	| null
+	| undefined
+	| ToJSON
+	| JSONValue[]
+	| JSONObject;
 
 export interface LoadInput<Params = Record<string, string>> {
 	url: URL;


Test patch:
diff --git a/packages/kit/test/typings/endpoint.test.ts b/packages/kit/test/typings/endpoint.test.ts
index f805a811d..9f5af8ec3 100644
--- a/packages/kit/test/typings/endpoint.test.ts
+++ b/packages/kit/test/typings/endpoint.test.ts
@@ -5,10 +5,11 @@ const valid_body = {
 	num: 12345,
 	bool: true,
 	null: null,
+	maybe: Math.random() < 0.5 ? undefined : true,
 	custom: {
 		toJSON: () => 'custom toJSON function'
 	},
-	list: ['string', 12345, false, null],
+	list: ['string', 12345, false, null, undefined],
 	nested: {
 		another: 'string',
 		big_num: 98765,
@@ -84,13 +85,6 @@ export const differential_headers_assignment: RequestHandler = () => {
 
 // --- invalid cases ---
 
-// @ts-expect-error - should not have undefined (should it not?)
-export const error_no_undefined: RequestHandler = () => {
-	return {
-		body: { no: Math.random() < 0.5 ? undefined : 'something' }
-	};
-};
-
 // @ts-expect-error - body must be JSON serializable
 export const error_body_must_be_serializable: RequestHandler = () => {
 	return {