Skip to content

Instantly share code, notes, and snippets.

@ValentinFunk
Created March 3, 2020 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ValentinFunk/d8e40655b8348f32ef5d868187bbc01f to your computer and use it in GitHub Desktop.
Save ValentinFunk/d8e40655b8348f32ef5d868187bbc01f to your computer and use it in GitHub Desktop.
Undiscriminiate in Typescript
type DiscriminateMessageType<
A,
T extends BookingMessageNotification['bookingMessageType']
> = A extends BookingMessageNotification ?
T extends A['bookingMessageType'] ? A : never
: never;
asMsg<T extends BookingMessageNotification['bookingMessageType']>(type: T): DiscriminateMessageType<BookingMessageNotification, T> {
return this._entry as any;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment