Repository: sveltejs/kit
Pull request #5118 (2022-05-30 16:12:35)

recurse whole object
We shouldn't be spreading the values but instead pass in the whole object or information would be lost when recursing. This was my mistake.

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [ ] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. All changesets should be `patch` until SvelteKit 1.0


changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 0b130176b8a1b51e1e35249f5b03f2f89437cb96

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/sveltejs/kit/new/recurse-whole-object?filename=.changeset/nine-rats-bake.md&value=---%0A%22%40sveltejs%2Fkit%22%3A%20patch%0A---%0A%0Arecurse%20whole%20object%0A)



Patch:
diff --git a/.changeset/nine-rats-bake.md b/.changeset/nine-rats-bake.md
new file mode 100644
index 000000000..4acce3d71
--- /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/types/private.d.ts b/packages/kit/types/private.d.ts
index d8fc6575d..60415dadb 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<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];


Test patch:
diff --git a/packages/kit/test/typings/endpoint.test.ts b/packages/kit/test/typings/endpoint.test.ts
index 6266c02a1..ffd03e48a 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<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