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
This is the behavior in every version I tried, and I reviewed the FAQ for entries about unions, 25, etc.
This reproduces in the Playground in the following versions: v3.9.7, v4.0.5, v4.1.3, v4.2.0-beta, v4.2.0-dev.20210127. I haven't tried any other versions.
exporttypeUnion1=|'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'I'|'J'|'K'|'L'|'M'exporttypeUnion2=|'N'|'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'functionone(arg: {val: Union1,other?: string}|{val: Union2}){}functiontwo(vals: Array<Union1|Union2>){vals.map(val=>one({ val }))}
🙁 Actual behavior
In this code, I have two (machine-generated) string unions, which I then want to use to create discriminated union in a function signature. This approach works fine if the total number of entries in the two unions is <=25, but once a 26th item is added to the two unions, a type error is raised.
The type error is in the one({ val }) call:
Argument of type '{ val: "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"; }' is not assignable to parameter of type '{ val: Union1; other?: string | undefined; } | { val: Union2; }'.
Type '{ val: "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"; }' is not assignable to type '{ val: Union2; }'.
Types of property 'val' are incompatible.
Type '"A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"' is not assignable to type 'Union2'.
Type '"A"' is not assignable to type 'Union2'.(2345)
This is incorrect because each val value that might be passed there is, by definition from the two function signature, a valid value from Union1 or Union2. Indeed, if you comment out a single item from either Union1 or Union2, you'll see that the type error goes away. I'm guessing there's a hard-coded limit somewhere of 25 that this is hitting.
🙂 Expected behavior
There should not be a type error, because the val in two's map is guaranteed to be Union1 | Union2 based on the type of vals, and therefore can always fulfill one side of the arg: { val: Union1, other?: string } | { val: Union2} union.
Thanks!
The text was updated successfully, but these errors were encountered:
Ah, ok, so it is a duplicate. I did find it, as you can see from my original report, but it wasn't clear to me that it was exactly a duplicate since the context of how the large union is generated and used is different. Apologies for the duplicate report!
@MartinJohns I assume we should we close this then?
Bug Report
🔎 Search Terms
25, union, limit, max
These other issues may be related:
🕗 Version & Regression Information
This reproduces in the Playground in the following versions: v3.9.7, v4.0.5, v4.1.3, v4.2.0-beta, v4.2.0-dev.20210127. I haven't tried any other versions.
⏯ Playground Link
Playground link with sample code
💻 Code
🙁 Actual behavior
In this code, I have two (machine-generated) string unions, which I then want to use to create discriminated union in a function signature. This approach works fine if the total number of entries in the two unions is <=25, but once a 26th item is added to the two unions, a type error is raised.
The type error is in the
one({ val })
call:This is incorrect because each
val
value that might be passed there is, by definition from thetwo
function signature, a valid value fromUnion1
orUnion2
. Indeed, if you comment out a single item from eitherUnion1
orUnion2
, you'll see that the type error goes away. I'm guessing there's a hard-coded limit somewhere of25
that this is hitting.🙂 Expected behavior
There should not be a type error, because the
val
intwo
'smap
is guaranteed to beUnion1 | Union2
based on the type ofvals
, and therefore can always fulfill one side of thearg: { val: Union1, other?: string } | { val: Union2}
union.Thanks!
The text was updated successfully, but these errors were encountered: