Maximum call stack size exceeded for getTypeAtFlowNode in Large File #14314
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Code
Discovered while trying to work around react/react-native#12590
For a large TS file that looks like:
const data = {} as any
data["a"] = "AH0";
data["a(1)"] = "EY1";
data["a's"] = "EY1 Z";
data["a."] = "EY1";
data["a.'s"] = "EY1 Z";
data["a.s"] = "EY1 Z";
... 100,000 + linesCompile the file on its own with tsc
Here's the complete file: https://gist.githubusercontent.com/mattbierner/34dbc249be0ebddedcc275d0ff40281b/raw/985dbbfba9a5db89f9cea618ce3c885ccc46ef8b/cmu.js
Bug
/XXX/node_modules/typescript/lib/tsc.js:51296
throw e;
^
RangeError: Maximum call stack size exceeded
at isMatchingReference (/XXX/node_modules/typescript/lib/tsc.js:27613:37)
at getTypeAtFlowAssignment (/XXX/node_modules/typescript/lib/tsc.js:28150:21)
at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28101:32)
at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28123:32)
at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28123:32)
at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28123:32)
at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Activity
mhegazy commentedon Feb 27, 2017
Every statement is considered a "narrowing" expression, and that triggers more analysis, if the compiler goes far enough in the statement list, it runs out of stack space.
have you considered writing it as an object literal?
or adding a type annotation with an index signature, e.g.
: { [x:string}: string }mjbvz commentedon Feb 28, 2017
Thanks Mohamed Hegazy (@mhegazy). I actually started with a json object but ran into some problems with react-native, which is why I tried to convert it to this format. Obviously the code is not terribly practical, but I also wasn't trying to break typescript or anything when doing this.
Adding an index signiture like so:
Does not fix things. I still see exceptions such as:
and
atifsyedali commentedon Jun 13, 2017
This is particularly problematic because it tends to break long locale files in large projects.
endel commentedon Aug 4, 2017
Still occurring on
typescript@2.4.2.As Atif Ali (@atifsyedali) said, this is quite problematic. I'm working with legacy code that has +5000 lines of assignments to a dictionary.
endel commentedon Aug 4, 2017
As a workaround, I'm using arrays and assigning later to the dictionary: