On this page
Readonly
Prev: `Required` | Up: object_transforms | Next: `Record`
Rel: object_transforms, Conditional & Mapped Types
Ref: TypeScript Docs — Utility Types
Tags: #public #web #typescript #utility-types #object_transforms #tier/core
Syntax & Overview
Readonly<T>
Marks every top-level property of T as readonly.
Notes & Pitfalls
- Shallowly marks all top-level properties
readonly: Compile-time only—pair withObject.freeze()if you also need runtime immutability.
Example
interface State { count: number; label: string }
const frozen: Readonly<State> = { count: 0, label: "init" };
// frozen.count = 1; // compile-time error
Linked from
Related notes
- tuts/typescript/utility_types/object_transforms/Record Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/object_transforms/Required Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/object_transforms Linked here; links to this page; shared tags: #typescript, #web
- tuts/typescript/tutorials/building_type_level_utilities links to this page; shared tags: #typescript, #web
- tuts/typescript/type_system/conditional_and_mapped_types Linked here; shared tags: #typescript, #web
- tuts/typescript/builtins/any shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/as_const shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/asserts shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/enum shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/infer shared tags: #tier, #typescript, #web