(no title)
wezm | 2 years ago
Edit: lots of replies showing how TypeScript can be made to do exhaustiveness checking. It's neat and all but it's a lot of gymnastics compared to languages that just have this built in, which again is part of the appeal of Gleam for me.
laurencerowe|2 years ago
klavinski|2 years ago
smj-edison|2 years ago
EDIT: and an example of usage: https://github.com/wwtos/mjuo/blob/ca8c514185c1b5bb22aec752a...
dcre|2 years ago
https://github.com/gvergnaud/ts-pattern
superice|2 years ago
function expectType<A, B extends A>() {}
expectType<never, typeof yourUnion>();
The function call will fail at compile time if yourUnion is anything more than never, which you can use in your else case of if statements that narrow the discriminated union.