TypeScript · Generics and utility types

as const

Makes literals readonly and narrow instead of widening to string[].

Syntax
["a", "b"] as const

Example

Example
const roles = ["admin", "learner"] as const;
type Role = typeof roles[number];

More in this group

Awaited<T> Generic constraint Generic function Indexed access keyof Parameters<T> Partial<T> Pick<T, K> / Omit<T, K>

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course