paldepind / union-type

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

Records can't have a "name" property #40

Closed kwijibo closed 8 years ago

kwijibo commented 8 years ago
const T = require("union-type")
var R = T({A: {name: String}})
var r = R.A("abc")
R.case({A: (i)=>console.log(i)}, r)

gives:

Error: non-exhaustive patterns in a function

because name is used for the subtype name A. This is then overwritten when you instantiate the record. So you can pass it to R.case but it won't match because the name property isn't A any more, but "ABC".

paldepind commented 8 years ago

I have prefixed the name property with a _ in the latest release. It should fix this issue.