stack

Home > @infiniteobjects/type-utils > ReadonlyDeep

ReadonlyDeep type

Convert objects, Maps, Sets, and Arrays and all of their keys/elements into immutable structures recursively.

Signature:

export type ReadonlyDeep<T> = T extends Primitive | ((...args: any[]) => unknown) ? T : T extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMapDeep<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? ReadonlySetDeep<ItemType> : T extends object ? ReadonlyObjectDeep<T> : unknown;

References: Primitive

Remarks

This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.