unsplash / sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
https://unsplash.github.io/sum-types/
MIT License
42 stars 2 forks source link

Non-function nullary constructors #45

Closed samhh closed 2 years ago

samhh commented 2 years ago

Fixes #44. This is the "some more exotic approach" alluded to at the end there.

This changes the library API as follows:

type Weather = Sum.Member<'Sun'> | Sum.Member<'Rain', number>
const Weather = Sum.create<Weather>()

// Before
Weather.mk.Sun()
Weather.mk.Rain(123)

// After
Weather.mk.Sun // <- no function call!
Weather.mk.Rain(123)