import { expectTypeOf, test } from "vitest"; import type { Field, PickIdValuesFromType } from ".."; // Construct sample fields including different types type SampleFields = [ { id: "title"; type: "text"; label: string }, { id: "firstButtonLink"; type: "url"; label: string }, { id: "count"; type: "number"; label: string }, { id: "isActive"; type: "boolean"; label: string } ] extends Field[] ? [ { id: "title"; type: "text"; label: string }, { id: "firstButtonLink"; type: "url"; label: string }, { id: "count"; type: "number"; label: string }, { id: "isActive"; type: "boolean"; label: string } ] : never; type Values = PickIdValuesFromType; test("field types map correctly to their value types", () => { // Text fields are string expectTypeOf().toHaveProperty("title"); expectTypeOf().toEqualTypeOf(); // Url fields are string (not string | boolean) expectTypeOf().toHaveProperty("firstButtonLink"); expectTypeOf().toEqualTypeOf(); // Number fields are number (not number | boolean) expectTypeOf().toHaveProperty("count"); expectTypeOf().toEqualTypeOf(); // Boolean fields are boolean only expectTypeOf().toHaveProperty("isActive"); expectTypeOf().toEqualTypeOf(); }); test("url fields expose _target boolean", () => { // And `${id}_target` exists as optional boolean expectTypeOf().toHaveProperty("firstButtonLink_target"); expectTypeOf().toMatchTypeOf(); // Non-url field should NOT have _target key // @ts-expect-error - title_target should not exist type _NoTitleTarget = Values["title_target"]; });