TypeScript · Generics and utility types

Readonly<T>

Makes all top-level properties readonly. It is shallow, so nested objects stay mutable.

Syntax
Readonly<User>

Example

Example
type User = { id: string };
const user: Readonly<User> = { id: "u1" };
// user.id = "u2";

More in this group

as const Awaited<T> Generic constraint Generic function Indexed access keyof Parameters<T> Partial<T>

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