Skip to content

Commit ef2cf5d

Browse files
JeanJPNMignatiusmb
andauthored
[chore] allow EndpointOutput response objects with toJSON property (#2170)
allows users to return objects with a custom toJSON property Co-authored-by: Ignatius Bagus <[email protected]>
1 parent 7c1d7e6 commit ef2cf5d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.changeset/thirty-frogs-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Allow `EndpointOutput` response body objects to have a `toJSON` property

packages/kit/types/endpoint.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import { ServerRequest } from './hooks';
22
import { Headers, MaybePromise } from './helper';
33

4-
type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
4+
type ToJSON = { toJSON(...args: any[]): JSONValue };
5+
type JSONValue = Exclude<JSONResponse, ToJSON>;
6+
type JSONResponse =
7+
| string
8+
| number
9+
| boolean
10+
| null
11+
| JSONResponse[]
12+
| ToJSON
13+
| { [key: string]: JSONResponse };
514

6-
type DefaultBody = JSONValue | Uint8Array;
15+
type DefaultBody = JSONResponse | Uint8Array;
716

817
export interface EndpointOutput<Body extends DefaultBody = DefaultBody> {
918
status?: number;

0 commit comments

Comments
 (0)