Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-readers-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

`RequestHandlerOutput` accepts body when it has or maybe is `undefined`
10 changes: 2 additions & 8 deletions packages/kit/test/typings/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion packages/kit/types/private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down