paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

Check if union covers all cases even if the current case is satisfied. #52

Open JAForbes opened 7 years ago

JAForbes commented 7 years ago

I'd like to receive a type error if a case function is missing cases. union-type already does this but it will only throw if the current case is missing - which makes it quite likely that you miss a substantial set of bugs ( and the main benefit of union types ).

An example:

const User = Type({
  Guest: []
  Registered: []
})

const registered = User.Registered()

User.case({
  Registered: console.log
}, registered)

The above doesn't fail, even though the case is not handling all domains. It should check if the case function has the same keys as the Type definition.