-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
At the moment if you define types with a following signatures:
const X = Record({x: 0}, 'X')
const Y = Record({y: 0}, 'Y')
const C = Record({ data: Union(X, Y) })Then type union interprets data value not always as one would expected:
C({data: {x: 2}}) // => Typed.Record({data: Union(X, Y)})({ "data": X({ "x": 2 }) })
C({data: X({x: 5})}) // => Typed.Record({data: Union(X, Y)})({ "data": X({ "x": 5 }) })
C({data: Y({y: 3})}) // => Typed.Record({data: Union(X, Y)})({ "data": Y({ "y": 3 }) })
C({data: {y: 2}}) // => Typed.Record({data: Union(X, Y)})({ "data": X({ "x": 0 }) })Most likely in last statement data field was expected to be an instance of Y instead of X, although given that {y: 2} can be read both as X and Y it was interpreted as a first type in the union X.
It maybe better to disallow passing untyped values all together in order to avoid this issue.
Metadata
Metadata
Assignees
Labels
No labels