Recursively applies the readonly modifier to all properties of an object, array, Map, or Set. Primitives and functions are returned as is.
readonly
The type to make deeply readonly.
A new type with all nested properties marked as readonly.
type Data = { a: number; b: { c: string[]; d: Map<number, boolean> } };type ReadonlyData = DeepReadonly<Data>;// Result: {// readonly a: number;// readonly b: {// readonly c: readonly string[];// readonly d: ReadonlyMap<number, boolean>;// };// } Copy
type Data = { a: number; b: { c: string[]; d: Map<number, boolean> } };type ReadonlyData = DeepReadonly<Data>;// Result: {// readonly a: number;// readonly b: {// readonly c: readonly string[];// readonly d: ReadonlyMap<number, boolean>;// };// }
Recursively applies the
readonlymodifier to all properties of an object, array, Map, or Set. Primitives and functions are returned as is.