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".
gives:
because
name
is used for the subtype nameA
. This is then overwritten when you instantiate the record. So you can pass it toR.case
but it won't match because thename
property isn'tA
any more, but"ABC"
.