diff --git a/.changeset/nine-rats-bake.md b/.changeset/nine-rats-bake.md new file mode 100644 index 000000000000..4acce3d71311 --- /dev/null +++ b/.changeset/nine-rats-bake.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +fix `BodyValidator` handling for nested object literals diff --git a/packages/kit/test/typings/endpoint.test.ts b/packages/kit/test/typings/endpoint.test.ts index 6266c02a1702..ffd03e48aac8 100644 --- a/packages/kit/test/typings/endpoint.test.ts +++ b/packages/kit/test/typings/endpoint.test.ts @@ -104,6 +104,23 @@ export const nested_interfaces: RequestHandler, ParentWra }; }; +interface NestedLiteral { + date: { + published: string; + updated?: string; + time: { + hour: number; + min: number; + sec?: number; + }; + }; +} +export const nested_literal: RequestHandler, NestedLiteral> = () => { + return { + body: {} as NestedLiteral + }; +}; + // --- invalid cases --- // @ts-expect-error - bigint cannot be converted to JSON string diff --git a/packages/kit/types/private.d.ts b/packages/kit/types/private.d.ts index d8fc6575d9a7..60415dadb900 100644 --- a/packages/kit/types/private.d.ts +++ b/packages/kit/types/private.d.ts @@ -27,8 +27,8 @@ export interface AdapterEntry { } export type BodyValidator = { - [P in keyof T]: T[P] extends { [k: string]: infer V } - ? BodyValidator // recurse when T[P] is an object + [P in keyof T]: T[P] extends { [k: string]: unknown } + ? BodyValidator // recurse when T[P] is an object : T[P] extends BigInt | Function | Symbol ? never : T[P];