TS ADVANCEDChapter 3 · TS Advanced
Readonly and as const
readonly stops a property from being reassigned, and readonly T[] removes changing methods like push. Writing as const after a literal locks the whole value: every property becomes readonly and every value keeps its exact literal type, so ["north", "south"] as const has the type readonly ["north", "south"]. These checks exist only at compile time; they catch mistakes before the code runs.
Worked example
How it reads
config.apiUrl = ...would be a compile error;retriescan changeas constkeeps each direction as its own literal type(typeof DIRECTIONS)[number]turns the array into the union of its values

Cloud tip: The
as const array plus [number] pattern gives you a runtime list and a matching type from one source.

