TypeScript Utility Types

Readonly<T> — shallow write restrictions

Readonly marks immediate properties readonly through a reference of that type. A nested mutable object can still be modified, and an alias with a mutable type may change the same value. For an array or tuple the homomorphic mapping also produces its readonly counterpart. It is not Object.freeze and does not make an independent copy. Example output: "2 1". Verified with strict TypeScript 5.8.3, ES2022 and Node.js 22.16.0. This utility affects static typing; no runtime validation or transformation is supplied by the type itself.

Formal Syntax & Structure

typescript syntaxtypescript
Readonly<T>

Parameters & Attributes

NameTypeDescription
Ttype parameterSource type to expose with readonly properties.

Working Example

Example Snippettypescript
type Model = { id: number; nested: { count: number } };const source: Model = { id: 1, nested: { count: 0 } };const view: Readonly<Model> = source;view.nested.count++;source.id = 2;console.log(view.id, view.nested.count);
TypeScript Reference