-
Notifications
You must be signed in to change notification settings - Fork 12.8k
"Type instantiation is excessively deep and possibly infinite." for big keyof types #35493
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
Comments
@weswigham this doesn't appear to me to be something that should trigger this error? |
This particular error crops up a lot in a lot of cases; while I agree that there needs to be a limit for sanity sake, it'd be really nice to be able to set that limit in tsconfig or at the very least increase it by 50-100%. |
Specifically, that change made it so we no longer try to instantiate unions of literals (neat). However the broader problem is thus: for each mapped type member, we instantiate the member type with the template mapper (to perform substitutions). In doing to, we perform instantiation on every member of the union. In this case, that meant for 2236 properties, we did 2236 instantiations per property, which is juuuust under the 5,000,000 global instantiations limit (so with lib stuff, easily over it). See, thing is, I really don't think noop instantiations like this should count towards that work limit. I may save/restore that counter such that it only increases when an instantiation operation actually produces a change (rather than just traversing a type). @ahejlsberg that make sense to you? |
I can't easily modify the test case to trigger under current |
@weswigham When I made the change, I was thinking of it as a perf enhancement that wouldn't change the semantics, so I didn't add a semantic test. I guess there's an extremity where a perf fix becomes a correctness fix, but I have mixed feelings about how valuable a regression test for such a change would be. Personally, I would probably just add a comment to the kick-out lining explaining that it can enable scenarios with very large string unions, so that it's not inadvertently removed. I might even go so far as to link this bug in the comment, but I don't think I'd make every test run slower to confirm that we don't regress this. |
"Make every test run slower" here being like 2-3 seconds, tops. It's not some monster 30s test or anything. |
I think the probability and impact of a regression are both small, so I'm not inclined to pay very much to avoid it. If you view the trade-off differently, then go ahead and add a test. |
Alright, I suppose I'll just close the issue, then. |
TypeScript Version: 3.7.2
Search Terms:
Expected behavior:
There isn't any error message in TypeScript v3.5.1
Actual behavior:

"Type instantiation is excessively deep and possibly infinite." message is emitted
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: