-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Distributive conditional type limit over 25 items? #46497
Comments
The limit of 25 is not a bug, but an intentional limit. Just search for |
Is this actually that limit, though? The error shown is just a normal assignability error; usually when TS hits the recursion limit it actually produces an error to that effect. |
@fatcerberus Yes: #43283. It's not a recursion limit. |
This seems a little different, in that the union type definition itself still works with greater than 25 items but only fails when used in a distributive conditional type. It also works in a non-distributive conditional type. Also, if there is indeed a 25-item limit somewhere, could the error message be improved to indicate that? Otherwise, it feels very arbitrary - we wasted a lot of time trying to figure out the problem when this is a known limitation. Also, there does not seem to be a canonical feature request issue for increasing this limit or making it configurable - they have all been closed. Can we please get a canonical one we could upvote and subscribe to? It would also it make it more discoverable. This feels like it should be added to the "known issues" section of the FAQ as well. |
From what I've been led to understand, the specific limit involved here is about relating |
Ah, that's consistent with the error message. OK, here's a more minimal repro: TS playground link. Inline: // 26 items
const things = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26] as const;
type Thing = typeof things[number];
type Wrapper<T> = { thing: T }
type DistributiveWrapper<T> = T extends Thing ? Wrapper<T> : never;
function foo(wrapper: DistributiveWrapper<Thing>): Wrapper<Thing> {
// works
return wrapper;
}
function bar(wrapper: Wrapper<Thing>): DistributiveWrapper<Thing> {
// doesnt work
return wrapper;
}
// Note, only 25 items
const things2 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25] as const;
type Thing2 = typeof things2[number];
function bar2(wrapper: Wrapper<Thing2>): DistributiveWrapper<Thing2> {
// works
return wrapper;
} |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
I'm not exactly sure what the bug is because it feels rather arbitrary, but I suspect there's some limit to distributive conditional types I'm running into. The repro below (tried to make it as minimal as possible) is the easiest way to demonstrate it.
The problem is I have a conditional type
Conditional<T>
where I pass inC = A | B
andB
itself is a union type composed of 26 items. In the conditional type, I branch onT extends A ? AWrapper<A> : T extends B ? BWrapper\<B\> : ....
.I then make Conditional the return type of a function, and try to return a simplified case of
BWrapper<B>
, but it fails to compile. The interesting part though is it only fails whenB
is a union type of 26 items and not when it's just 25 items.Everything also works if I change the conditional type to be non-distributive:
[T] extends [A] ? AWrapper<A> : [T] extends [B] ? BWrapper<B> : ...
I'm sure a suggestion might be to make
Conditional
a union type ofAWrapper<A> | BWrapper<B>
here instead of a conditional type, but I explain why at the bottom I'd prefer to avoid that.In summary, I'm not sure why when
B
is > 25 items it doesn't work.🔎 Search Terms
25 26 enum distributive conditional type limit
🕗 Version & Regression Information
I see this bug in all versions of TS that are usable in the TS playground
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Error:
🙂 Expected behavior
No error, which is what happens in the non-distributive case or the case where
FieldWithoutId
only contains 25 items.The text was updated successfully, but these errors were encountered: