paldepind / union-type

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

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

Open JAForbes opened 8 years ago

JAForbes commented 8 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.