From c744ffa2119e3b981b9daba5afb5100e40d9fc0c Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 21 Oct 2023 20:49:29 +0100 Subject: [PATCH 1/2] fix: recursively simplify returned objects --- src/types/serialize.ts | 2 +- test/fixture/types.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/types/serialize.ts b/src/types/serialize.ts index 23546cb609..80e0f86b51 100644 --- a/src/types/serialize.ts +++ b/src/types/serialize.ts @@ -53,4 +53,4 @@ type SerializeObject = { */ export type Simplify = TType extends any[] | Date ? TType - : { [K in keyof TType]: TType[K] }; + : { [K in keyof TType]: Simplify }; diff --git a/test/fixture/types.ts b/test/fixture/types.ts index f0403b22d5..f02bc3d055 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -3,6 +3,7 @@ import { describe, it } from "vitest"; import { EventHandler, EventHandlerRequest, defineEventHandler } from "h3"; import { $Fetch } from "../.."; import { defineNitroConfig } from "../../src/config"; +import { Serialize, Simplify } from "../../src/types" interface TestResponse { message: string; @@ -307,3 +308,17 @@ describe("defineCachedEventHandler", () => { >(); }); }); + +describe('type helpers', () => { + it('Serialize', () => { + expectTypeOf>().toEqualTypeOf<{ test: string }>() + expectTypeOf }>>().toEqualTypeOf<{ test: Record }>() + expectTypeOf } }>>().toEqualTypeOf<{ nested: { test: Record } }>() + }) + + it('Simplify', () => { + expectTypeOf>>().toEqualTypeOf<{ test: string }>() + expectTypeOf }>>>().toEqualTypeOf<{ test: Record }>() + expectTypeOf } }>>>().toEqualTypeOf<{ nested: { test: Record } }>() + }) +}) From e7a405461b00ab802ac851bab8029a0b9c3bb41a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:51:21 +0000 Subject: [PATCH 2/2] chore: apply automated fixes --- test/fixture/types.ts | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/test/fixture/types.ts b/test/fixture/types.ts index f02bc3d055..fc41544e2a 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -3,7 +3,7 @@ import { describe, it } from "vitest"; import { EventHandler, EventHandlerRequest, defineEventHandler } from "h3"; import { $Fetch } from "../.."; import { defineNitroConfig } from "../../src/config"; -import { Serialize, Simplify } from "../../src/types" +import { Serialize, Simplify } from "../../src/types"; interface TestResponse { message: string; @@ -309,16 +309,26 @@ describe("defineCachedEventHandler", () => { }); }); -describe('type helpers', () => { - it('Serialize', () => { - expectTypeOf>().toEqualTypeOf<{ test: string }>() - expectTypeOf }>>().toEqualTypeOf<{ test: Record }>() - expectTypeOf } }>>().toEqualTypeOf<{ nested: { test: Record } }>() - }) +describe("type helpers", () => { + it("Serialize", () => { + expectTypeOf>().toEqualTypeOf<{ test: string }>(); + expectTypeOf }>>().toEqualTypeOf<{ + test: Record; + }>(); + expectTypeOf< + Serialize<{ nested: { test: Map } }> + >().toEqualTypeOf<{ nested: { test: Record } }>(); + }); - it('Simplify', () => { - expectTypeOf>>().toEqualTypeOf<{ test: string }>() - expectTypeOf }>>>().toEqualTypeOf<{ test: Record }>() - expectTypeOf } }>>>().toEqualTypeOf<{ nested: { test: Record } }>() - }) -}) + it("Simplify", () => { + expectTypeOf>>().toEqualTypeOf<{ + test: string; + }>(); + expectTypeOf< + Simplify }>> + >().toEqualTypeOf<{ test: Record }>(); + expectTypeOf< + Simplify } }>> + >().toEqualTypeOf<{ nested: { test: Record } }>(); + }); +});