Created
April 21, 2023 16:33
-
-
Save azerum/27c18825eb992301fec8d489a8afa419 to your computer and use it in GitHub Desktop.
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
| export type DeepReadonly<T> = | |
| //Functions are objects, but don't need to be deep readonly | |
| T extends Function ? T : | |
| T extends Map<infer MK, infer MV> ? ReadonlyMap<DeepReadonly<MK>, DeepReadonly<MV>> : | |
| T extends Set<infer E> ? ReadonlySet<DeepReadonly<E>> : | |
| T extends Array<infer E> ? ReadonlyArray<DeepReadonly<E>> : | |
| T extends object ? DeepReadonlyObject<T> : | |
| T; | |
| type DeepReadonlyObject<T> = { | |
| readonly [K in keyof T]: DeepReadonly<T[K]>; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment