Dev Helpers
← Back

Derive array length as a literal

Derive array length as a literal 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(((n: (typeof statuses)["length"]) => n)(3));

Sample output

3