TypeScript · Types and shapes
Readonly
Prevents reassignment of the property after creation. It is shallow and checked only by the compiler.
Syntax
readonly id: stringExample
Example
type User = { readonly id: string; name: string };
const user: User = { id: "u1", name: "Ada" };
// user.id = "u2";More in this group
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.