Skip to content

Instantly share code, notes, and snippets.

View tylerbrostrom's full-sized avatar

Tyler Brostrom tylerbrostrom

View GitHub Profile
@tylerbrostrom
tylerbrostrom / discriminating-union.ts
Last active May 27, 2021 00:07
TypeScript Utility for Creating Discriminating Unions
/**
Create a discriminating union type from two or more object types.
Why?:
- Saves you a few keystrokes.
- Esp. helpful for distinguishing between type aliases you don’t own.
Caveats:
- Discriminator property might clobber an existing property.