Dev Helpers
← Back

Build per-field validators

Build per-field validators using TypeScript.

Open this example in the interactive library

Source code

type Settings = { theme: string; limit: number; debug: boolean };
const settings: Settings = { theme: "dark", limit: 4, debug: false };
console.log(
  (
    {
      theme: (v) => v.length > 0,
      limit: (v) => v > 0,
      debug: (v) => typeof v === "boolean",
    } satisfies { [K in keyof Settings]: (v: Settings[K]) => boolean }
  ).limit(3),
);

Sample output

true