[chore] allow `EndpointOutput` response objects with `toJSON` property
allows users to return objects with a custom toJSON property
ADD
.changeset/thirty-frogs-mix.md
+---
+'@sveltejs/kit': patch
+---
+
+Allow `EndpointOutput` response body objects to have a `toJSON` property

MODIFY
packages/kit/types/endpoint.d.ts
packages/kit/types/endpoint.d.ts
import { ServerRequest } from './hooks';
import { Headers, MaybePromise } from './helper';
-type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
+type ToJSON = { toJSON(...args: any[]): JSONValue };
+type JSONValue = Exclude<JSONResponse, ToJSON>;
+type JSONResponse =
+ | string
+ | number
+ | boolean
+ | null
+ | JSONResponse[]
+ | ToJSON
+ | { [key: string]: JSONResponse };
-type DefaultBody = JSONValue | Uint8Array;
+type DefaultBody = JSONResponse | Uint8Array;
export interface EndpointOutput<Body extends DefaultBody = DefaultBody> {
status?: number;

[chore] allow `EndpointOutput` response objects with `toJSON` property (#2170)

allows users to return objects with a custom toJSON property

Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com>