diff --git a/src/types/serialize.ts b/src/types/serialize.ts index c971bc6c82..2442560a3d 100644 --- a/src/types/serialize.ts +++ b/src/types/serialize.ts @@ -28,7 +28,7 @@ type FilterKeys = { // prettier-ignore export type Serialize = IsAny extends true ? any : - T extends JsonPrimitive ? T : + T extends JsonPrimitive | undefined ? T : T extends Map | Set ? Record : T extends NonJsonPrimitive ? never : T extends { toJSON(): infer U } ? U : diff --git a/test/fixture/types.ts b/test/fixture/types.ts index a727546446..9e2624344f 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -311,7 +311,14 @@ describe("defineCachedEventHandler", () => { describe("type helpers", () => { it("Serialize", () => { + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf<{ + test?: string; + }>(); expectTypeOf>().toEqualTypeOf<{ test: string }>(); + expectTypeOf>().toEqualTypeOf<{ + test?: string; + }>(); expectTypeOf }>>().toEqualTypeOf<{ test: Record; }>();