Wish sum types got more love in TypeScript.<p>I have settled on this style to minimize the boilerplate code needed to write tagged unions and tagged union factories.<p>Lines 1-8 are helper functions for declaring tagged union types. They are used for non-generic tagged unions.<p>Non-generic tagged unions' types should be inferred correctly.<p>Generic tagged unions are super hard to type, as TypeScript only allows functions to be typed as generic values.<p>Wish you enjoy this as well.