Skip to content

Error since upgrading to 1.6.1 #263

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
quentez opened this issue Jan 16, 2019 · 4 comments
Closed

Error since upgrading to 1.6.1 #263

quentez opened this issue Jan 16, 2019 · 4 comments
Assignees
Labels

Comments

@quentez
Copy link

quentez commented Jan 16, 2019

We're making extensive use of Tagged Unions, and since upgrading to 1.6.1 we're now getting an error right when we declare our types:

image

Everything was working well in 1.6.0.

Our use-case in that file is pretty big and I can't just post it here. I'll have to try and reproduce it with a simpler case. The only thing I can see right now is that we're building a Tagged Union of Intersections (with the tag property being in one branch of the intersection).

@gcanti
Copy link
Owner

gcanti commented Jan 17, 2019

@quentez not sure if is the same bug but the following throws with the same message

// Note: this intersection always fails while decoding a value
const A = t.intersection([t.type({ type: t.literal('A') }), t.type({ type: t.literal('B') })])
const B = t.type({ type: t.literal('B') })
const C = t.taggedUnion('type', [A, B])

@gcanti gcanti added the bug label Jan 17, 2019
@gcanti gcanti self-assigned this Jan 17, 2019
@gcanti
Copy link
Owner

gcanti commented Jan 18, 2019

@quentez looks like the issue is also related to io-ts not being able to build a tagged union under some conditions.

We're making extensive use of Tagged Unions

I need your help, I just released a patch (1.6.4) that should fix this issue.
I also added a warning to the console if I can't build a tagged union.

Example

const A = t.type({ type: t.literal('A'), a: t.number }, 'A')
const B = t.refinement(A, x => x.a > 0, 'B')
const T = t.taggedUnion('type', [B, A]) // type-checks but T is not a tagged union

In this case taggedUnion does two things:

  • prints to the console a warning (like "[io-ts] Cannot build a tagged union for (B | A), returning a de-optimized union")
  • returns a de-optimized union

Could you please try it out?

@quentez
Copy link
Author

quentez commented Jan 18, 2019

@gcanti Version 1.6.4 is working without any issue.
(And I'm not seeing the warning, so that's good).

Thank you for the super quick turnaround 🙂 !

@gcanti
Copy link
Owner

gcanti commented Jan 19, 2019

@quentez great, thanks for the bug report and the feedback

@gcanti gcanti closed this as completed Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants