Skip to content

Bug: taggedUnion doesn't handle sub unions / tagged unions correctly #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gcanti opened this issue Jan 15, 2019 · 0 comments · Fixed by #258
Closed

Bug: taggedUnion doesn't handle sub unions / tagged unions correctly #257

gcanti opened this issue Jan 15, 2019 · 0 comments · Fixed by #258
Assignees
Milestone

Comments

@gcanti
Copy link
Owner

gcanti commented Jan 15, 2019

Repro

const A = t.type({ type: t.literal('A') })
const B = t.type({ type: t.literal('B') })
const C = t.type({ type: t.literal('C') })
const SubUnion = t.union([A, B])
const T = t.taggedUnion('type', [SubUnion, C])
console.log(T.decode({ type: 'B' }).isRight()) // false, should be true
const A = t.type({ type: t.literal('A') })
const B = t.type({ type: t.literal('B') })
const C = t.type({ type: t.literal('C') })
const SubTaggedUnion = t.taggedUnion('type', [A, B])
const T = t.taggedUnion('type', [SubTaggedUnion, C])
console.log(T.decode({ type: 'B' }).isRight()) // false, should be true
@gcanti gcanti added this to the 1.6.1 milestone Jan 15, 2019
@gcanti gcanti self-assigned this Jan 15, 2019
gcanti added a commit that referenced this issue Jan 15, 2019
…ly, closes #257

Experimental: optimize union with the same algorithm used in taggedUnion

Also removed the following useless internal APIs

- isTagged
- findTagged
- getTagValue
gcanti added a commit that referenced this issue Jan 15, 2019
…ly, closes #257

Experimental: optimize union with the same algorithm used in taggedUnion

Also removed the following useless internal APIs

- isTagged
- findTagged
- getTagValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant