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

Fix `matchXW` failed pattern match when return value is `undefined` #57

Closed mlegenhausen closed 1 year ago

mlegenhausen commented 1 year ago

Currently it is not possible to use undefined as return value for matchXW. This PR solves this use by using the in operator to check for the existence of a tag instead of comparing with undefined.

mlegenhausen commented 1 year ago

No, because all values are always wrapped in a closure, but we could align the implementations so we don't have two strategies. WDYT?

samhh commented 1 year ago

Just noticed this should also fix matchX: https://github.com/unsplash/sum-types/pull/57/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80L281

Would be good to add a test case for that as well.

We could align the implementations so we don't have two strategies. WDYT?

There's certainly more duplication than I'd like.

mlegenhausen commented 1 year ago

Ah I misread you meant matchX not match. Yes it had the same problem because it is an alias.

mlegenhausen commented 1 year ago

@samhh could you publish a bugfix release? Thanks.