Skip to content

Commit

Permalink
recurse whole object (#5118)
Browse files Browse the repository at this point in the history
* failing test

* simple yet breaking oversight

* add changeset
  • Loading branch information
ignatiusmb authored May 30, 2022
1 parent 373ff63 commit b74e1e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-rats-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix `BodyValidator` handling for nested object literals
17 changes: 17 additions & 0 deletions packages/kit/test/typings/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ export const nested_interfaces: RequestHandler<Record<string, string>, ParentWra
};
};

interface NestedLiteral {
date: {
published: string;
updated?: string;
time: {
hour: number;
min: number;
sec?: number;
};
};
}
export const nested_literal: RequestHandler<Record<string, string>, NestedLiteral> = () => {
return {
body: {} as NestedLiteral
};
};

// --- invalid cases ---

// @ts-expect-error - bigint cannot be converted to JSON string
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/types/private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export interface AdapterEntry {
}

export type BodyValidator<T> = {
[P in keyof T]: T[P] extends { [k: string]: infer V }
? BodyValidator<V> // recurse when T[P] is an object
[P in keyof T]: T[P] extends { [k: string]: unknown }
? BodyValidator<T[P]> // recurse when T[P] is an object
: T[P] extends BigInt | Function | Symbol
? never
: T[P];
Expand Down

0 comments on commit b74e1e5

Please sign in to comment.