DeepReadonly: T extends (...args: readonly never[]) => unknown
    ? T
    : T extends null
    | undefined
    | boolean
    | number
    | string
    | bigint
        ? T
        : T extends (infer K)[]
            ? readonly DeepReadonly<K>[]
            : T extends Map<infer K, infer V>
                ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
                : T extends Set<infer V>
                    ? ReadonlySet<DeepReadonly<V>>
                    : { readonly [P in keyof T]: DeepReadonly<T[P]> }

Modify a given type T such that all its entries / properties are readonly, diving arbitrarily deeply (in contrast to the built-in Readonly<T>).

Type Parameters

  • T

    the type to make readonly.