Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
discriminated union discriminate out
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
You can’t perform that action at this time.