Created
July 18, 2019 07:49
-
-
Save sanex3339/85822811de5722c24197c0d7a7b5c6e2 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
type UnionKeys<T> = T extends any ? keyof T : never; | |
type StrictUnionHelper<T, TAllKeys extends PropertyKey> = T extends any | |
? T & Partial<Record<Exclude<TAllKeys, keyof T>, never>> | |
: never; | |
/** | |
* Тип для правильной работы Discriminated Union типов | |
* https://stackoverflow.com/questions/52677576/typescript-discriminated-union-allows-invalid-state/52678379#52678379 | |
*/ | |
export type StrictUnion<T> = StrictUnionHelper<T, UnionKeys<T>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment