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
“Type instantiation is excessively deep and possibly infinite” but only in a large codebase #34933
Comments
That's a lot of properties ._. |
|
@AnyhowStep That's correct. The component in question mixes-in the props defined by |
|
We have the same issue in one of our larger projects. Works fine with 3.6.4 but not with 3.7.2 Using type |
|
Same issue, using |
|
in So the value is hard-coded. Perhaps a configuration option to change this might be warranted. As a workaround for now, you could try upping this limit and rebuilding the compiler. |
|
There have been proposals made to increase the limit. They've been rejected because it's seen as an "implementation detail" that should not be exposed. PR: #29602 Comment by @ahejlsberg
I agree with this part,
If you're writing library code, you should not be messing with this limit. If you're writing application code and can force everyone on your team to use a hacked version of TS... You can go ahead and hack the .js files for tsc and tsserver. Then, use https://www.npmjs.com/package/patch-package and commit the patch files |
|
@Stianhn @rista404 Have you managed to reproduce this issue using a more reduced example? If what we're dealing with is a valid use case, then understanding it could help us come up with a heuristic for when type instantiation limit should not be applied. I agree that messing with the internals leads nowhere — after all, you need to draw the boundary somewhere. As far as I know, this limit is not something new. It existed before, yet somehow this code stopped working. I wonder what changed that directly influenced our use cases. |
|
git bisect? =x |
|
Can you grant @weswigham permission to the repository as well? |
|
@DanielRosenwasser Yes! Invite sent @weswigham. |
|
Another example in https://github.com/elastic/kibana/pull/47188/checks?check_run_id=303150613 where @timroes is trying to upgrade TS to 3.7.2: Related pull request: Related file: edit: this issue will be fixed with the aforementioned pull request. We've added an explicit intermediary type (elastic/kibana@ef912fc) that resolves the issue for 3.7. |
|
Worth noting that if you're upgrading from TS 3.5, something about how I'm bringing this up because it looks like @dgieselaar is migrating from TS 3.5 I also have a todo on my personal project to investigate this, AnyhowStep/tsql#25 But I'm not focusing on TS 3.7 support yet |
|
We have a similar issue with this code (roughly): |
|
I have a similar issue with grommet-icons v4.4.0: If I use the trash icon directly, all fine. If I wrap it with styled from styled component, I get the same message. No problem until typescript 3.5.2. No Problem: Problem with 3.7.2: |
|
Same issue with styled components extending rmwc components: import * as React from 'react'
import styled from 'styled-components'
import { Button } from '@rmwc/button'
const ButtonStyled = styled(Button)`
`
export function ConnectionSetting() {
return <React.Fragment>
<ButtonS />
</React.Fragment>
} |
|
So what is the fix here. Nothing yet ? and we should not update to latest ts ? or refactor application code within limits ? |
Guys, please show your interest in #44997 (thumb up!) to resolve the issue fasterCurrently, the limitation thresholds are hard-coded, to src/compiler/checker.ts if (
instantiationDepth === 50 ||
instantiationCount >= 5000000
) {
// We have reached 50 recursive type instantiations and there is a very high likelyhood we're dealing
// with a combination of infinite generic types that perpetually generate new type identities. We stop
// the recursion here by yielding the error type.
error(
currentNode,
Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite
);
return errorType;
}To make this configurable, I pushed a PR #44997, which makes those values be able to be set by {
"compilerOptions": {
"instantiationDepthLimit": 100,
"instantiationCountLimit": 10000000
}
}Though the PR is incomplete, just showing your interest would make its priority higher. Thanks. |
|
in the meantime, one can use patch-package to create a per-project patch to implement the temporary fix:
should end up something like this in the diff --git a/node_modules/typescript/lib/tsc.js b/node_modules/typescript/lib/tsc.js
index 78c5ec2..7d6c586 100644
--- a/node_modules/typescript/lib/tsc.js
+++ b/node_modules/typescript/lib/tsc.js
@@ -49264,7 +49265,7 @@ var ts;
if (!couldContainTypeVariables(type)) {
return type;
}
- if (instantiationDepth === 50 || instantiationCount >= 5000000) {
+ if (instantiationDepth === (50 * 2) || instantiationCount >= (5000000 * 2)) {
ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes", "instantiateType_DepthLimit", { typeId: type.id, instantiationDepth: instantiationDepth, instantiationCount: instantiationCount });
error(currentNode, ts.Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
return errorType;
{
"name": "...",
"workspaces": {
"packages": [
"...",
"..."
],
"nohoist": [
"typescript",
"typescript/**"
]
},Note: after some testing, it seems there's no value that's enough at least for my use case, even though it is not infinitely recursive... P.S. If a project is using something like If someone finds this - please let me know. |
|
I getting this error in an absurd way in server-side express based app: works, but ends up with firing this Note: ts config is following: |
|
@koteisaev See my comments above. Its an issue with the |
|
TypeScript team - is there any thought of putting in some syntax that could help guide the compiler during inference beyond a heuristic? For libraries that do schema translation this is going to be a continual headache. Perhaps something like a // This is a fully resolved type that the compiler knows the user really really wants to happen so go nuts and cache it
type ResolvedType = resolve DeeplyRecursiveType<string, Person>
//This also gives a caching point for each type it is given;
type MySchemaMapper<T> = resolve DeeplyRecursiveType<string, T>
//Using the above case this:
type MappedPerson = MySchemaMapper<string, Person>
//is equivalent to this:
type MappedPerson = resolve DeeplyRecursiveType<string, Person> Intellisense could also benefit from this as a lot of mapped types end up being unreadable as they show complicated expansions. If the |
|
All type instantiations are already cached. |
I had to change parameter name to a different yet similar for that URL, as a hotfix. |
|
The depth fix mentioned in this article resolved my problem, even when sticking to an initial depth of 1 I would love to know why |
|
It is possible to avoid Subj. issue in certain use cases by utilising UnionToIntersection metafunction as shown in the following SO answer: |
karol-majewski commentedNov 6, 2019
•
edited
TypeScript Version: 3.7.2, 3.8.0-dev.20191102 (worked in 3.6)
Search Terms:
Code
Note: this issue manifests itself only in our codebase. When you run the same code in TypeScript Playground, it seems to be working fine.
The snippet is hardly minimal, but I reduced it as much as I could. I recorded a video where exactly the same code yields an error different than the one in TypeScript Playground. I tried with two versions of TypeScript:
3.7.2and3.8.0-dev.20191102. It worked correctly with3.6.Since @sheetalkamat and @DanielRosenwasser have access to our repository, you're welcome to have a look at this PR. Copy-paste the code below anywhere in the project to see the error.
The versions of types used:
@types/history@4.7.3@types/react@16.9.11@types/react-router-dom@5.1.0@types/recompose@0.30.7Note: Interestingly enough, if you change:
it works again despite the fact
Omit<Props, never>should be the same as justProps.Source code
Expected behavior:
I should get a proper error about missing properties (not the one about type instantiation):
Actual behavior:
I'm getting this:
Playground Link:
Playground Link
Related Issues:
The text was updated successfully, but these errors were encountered: