Created
April 9, 2019 16:51
-
-
Save ValentinFunk/85a8204b39e7c73f41c2eaf7c2ec2f57 to your computer and use it in GitHub Desktop.
discriminated union discriminate out
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 Discriminate< | |
Union, | |
Prop extends keyof Union, | |
Discriminator extends Union[Prop], | |
> = Union extends { [T in Prop]: Extract<Union[Prop], Discriminator> } ? Union : never; | |
export type DiscriminateByType< | |
Union extends { type: any }, | |
D extends Union['type'] | |
> = Discriminate<Union, 'type', D>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment