From 51e0ea332f324da4c4b366ce27f194835b285a27 Mon Sep 17 00:00:00 2001 From: Jacob Heric Date: Mon, 10 Nov 2025 14:13:36 -0500 Subject: [PATCH] possible event schema type --- packages/local/test/foo.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/local/test/foo.test.ts diff --git a/packages/local/test/foo.test.ts b/packages/local/test/foo.test.ts new file mode 100644 index 0000000..ab39cfd --- /dev/null +++ b/packages/local/test/foo.test.ts @@ -0,0 +1,30 @@ +import { expectTypeOf, test } from "vitest"; + +type Wrapper = T extends { schema: infer S } ? S : never; + +export function foo( + arr: T +): Wrapper[] { + return arr.map((item) => item.schema) as Wrapper[]; +} + +test("infers union of schema types with literal types", () => { + const result = foo([{ schema: 1 }, { schema: "a" }]); + expectTypeOf(result).toEqualTypeOf<(1 | "a")[]>(); +}); + +test("infers object and boolean schema types with literal types", () => { + const result = foo([{ schema: { x: 42 } }, { schema: true }]); + expectTypeOf(result).toEqualTypeOf<({ readonly x: 42 } | true)[]>(); +}); + +test("infers single-element array with literal type", () => { + const result = foo([{ schema: 123 }]); + expectTypeOf(result).toEqualTypeOf<123[]>(); +}); + +test("preserves literal tuple inference when using const assertions", () => { + const input = [{ schema: 1 }, { schema: "a" }] as const; + const result = foo(input); + expectTypeOf(result).toEqualTypeOf<(1 | "a")[]>(); +});