File size: 409 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/**
* A type that represents a deeply readonly object. This is similar to
* TypeScript's `Readonly` type, but it recursively applies the `readonly`
* modifier to all properties of an object and all elements of arrays.
*/
export type DeepReadonly<T> = T extends (infer R)[]
? ReadonlyArray<DeepReadonly<R>>
: T extends object
? {
readonly [K in keyof T]: DeepReadonly<T[K]>
}
: T
|