← All tips

TypeScript: const assertions for literal types

typescripttyping

Keep values as literals with as const.

const roles = ['admin', 'user'] as const;
type Role = (typeof roles)[number];