UNPKG

1.14 kBTypeScriptView Raw
1import { AnyArray } from "../any-array";
2import { Builtin } from "../built-in";
3import { IsTuple } from "../is-tuple";
4import { IsUnknown } from "../is-unknown";
5export type DeepReadonly<Type> = Type extends Exclude<Builtin, Error> ? Type : Type extends Map<infer Keys, infer Values> ? ReadonlyMap<DeepReadonly<Keys>, DeepReadonly<Values>> : Type extends ReadonlyMap<infer Keys, infer Values> ? ReadonlyMap<DeepReadonly<Keys>, DeepReadonly<Values>> : Type extends WeakMap<infer Keys, infer Values> ? WeakMap<DeepReadonly<Keys>, DeepReadonly<Values>> : Type extends Set<infer Values> ? ReadonlySet<DeepReadonly<Values>> : Type extends ReadonlySet<infer Values> ? ReadonlySet<DeepReadonly<Values>> : Type extends WeakSet<infer Values> ? WeakSet<DeepReadonly<Values>> : Type extends Promise<infer Value> ? Promise<DeepReadonly<Value>> : Type extends AnyArray<infer Values> ? Type extends IsTuple<Type> ? {
6 readonly [Key in keyof Type]: DeepReadonly<Type[Key]>;
7} : ReadonlyArray<DeepReadonly<Values>> : Type extends {} ? {
8 readonly [Key in keyof Type]: DeepReadonly<Type[Key]>;
9} : IsUnknown<Type> extends true ? unknown : Readonly<Type>;