You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, the explicit string literals work well while the maps do not. I get the following TS compiler error:
Argument of type 'LiteralC<"value_a" | "value_b" | "value_c">[]' is not assignable to parameter of type '[Mixed, Mixed, ...Mixed[]]'.
Source provides no match for required element at position 0 in target.ts(2345)
Here's a screenshot in VSCode
Expected behavior
t.union(stringsArray.map(t.literal) compiles and works properly.
Reproducible example
See above
Suggested solution(s)
I'm not a deep expert on the io-ts library, so I don't yet know how to solve this. I'm happy to learn more tho and contribute a PR if there's someone on the team willing to point me in the right direction.
Or perhaps I'm missing something here and there's an obvious way to do what I'm trying to do here.
Your environment
Which versions of io-ts are affected by this issue? Did this work in previous versions of io-ts?
The problem is that union accepts at least two elements else creating a union makes no sense as you could for one element use the codec directly and you need to define what needs to happen when the array is empty.
In this case also the const does not make sure that you have at least two element as the map function converts your triple back to an array. You can get this working by using map only on the "rest" of your array and make sure that you have at least two elements. This looks something like this:
🐛 Bug report
Current Behavior
I would expect
tMyEnumValue
to be equivalent to the following:However, the explicit string literals work well while the maps do not. I get the following TS compiler error:
Here's a screenshot in VSCode
Expected behavior
t.union(stringsArray.map(t.literal)
compiles and works properly.Reproducible example
See above
Suggested solution(s)
I'm not a deep expert on the
io-ts
library, so I don't yet know how to solve this. I'm happy to learn more tho and contribute a PR if there's someone on the team willing to point me in the right direction.Or perhaps I'm missing something here and there's an obvious way to do what I'm trying to do here.
Your environment
Which versions of io-ts are affected by this issue? Did this work in previous versions of io-ts?
The text was updated successfully, but these errors were encountered: