Created
January 30, 2019 11:43
-
-
Save rodrigocfd/02b16ddda0a3239ad757f8a189a141af to your computer and use it in GitHub Desktop.
TypeScript DeepReadonly generic type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type DeepReadonly<T> = | |
| T extends (infer R)[] ? DeepReadonlyArray<R> : | |
| T extends Function ? T : | |
| T extends object ? DeepReadonlyObject<T> : | |
| T; | |
| interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> { } | |
| type DeepReadonlyObject<T> = { | |
| readonly [P in keyof T]: DeepReadonly<T[P]>; | |
| }; | |
| export default DeepReadonly; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment