Dev Helpers
← Back

Check a string against literal values

Check a string against literal values using TypeScript.

Open this example in the interactive library

Source code

const statuses = ["queued", "running", "done"] as const;
type Status = (typeof statuses)[number];
console.log(
  ((s: string): s is Status => statuses.some((v) => v === s))("unknown"),
);

Sample output

false