Readonly<T>
The utility type that marks every top-level property of T as readonly.
In more detail
Readonly<Pick<UserEntity, "id" | "email">> gives a public profile that cannot be changed by mistake. Like the readonly modifier it is shallow and checked only at compile time.
Related terms
- readonly — A modifier, in languages such as C# and TypeScript, that lets a field or property be assigned only when it is initialised, never afterwards.
- Pick<T, K> — The utility type that keeps only the listed keys K of type T, like an allowlist of fields.
- utility types — Generic types built into TypeScript, such as Partial, Pick and ReturnType, that compute a new type from an existing one.
Taught in
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript