Created
October 1, 2021 17:26
-
-
Save aiya000/950c3cb649e0a8742c11c8fc01bdd421 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Exposes type functions. | |
*/ | |
/** | |
* [Reference](https://stackoverflow.com/questions/42999983/typescript-removing-readonly-modifier) | |
*/ | |
export type DeepMutable<T> = { | |
-readonly [P in keyof T]: DeepMutable<T[P]>; | |
}; | |
/** | |
* A deeply `Readonly<T>`. | |
*/ | |
export type DeepReadonly<T> = { | |
readonly [P in keyof T]: DeepReadonly<T[P]>; | |
}; | |
/** | |
* A dual of [[DeepMutable]]. | |
*/ | |
export type DeepImmutable<T> = DeepReadonly<T>; | |
/** | |
* A proof to check that [[DeepMutable]] allows assignments. | |
*/ | |
const _proofDeepMutable = () => { | |
const _x: DeepMutable<{ | |
readonly xx: { | |
readonly xxx: number; | |
}; | |
}> = { xx: { xxx: 42 } }; | |
_x.xx.xxx = 10; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment