Description
I was testing some of my code in TS 3.6 and TS 3.7
Code that worked fine in TS 3.5.1 now got the Type_instantiation_is_excessively_deep_and_possibly_infinite
error instead.
I decided to do a little investigation and noticed that there was this thing called constraintDepth
with a limit of 50
. This was what was triggering the error.
I tried to disable the check for this constraintDepth
and, predictably, got the error,
return mapper(type);
^
RangeError: Maximum call stack size exceeded
at instantiateTypeWorker (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42582:24)
at instantiateType (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42575:26)
at /home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42274:42
at Object.map (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:507:29)
at getConditionalTypeInstantiation (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42537:40)
at instantiateTypeWorker (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42620:24)
at instantiateType (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42575:26)
at /home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42274:42
at Object.map (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:507:29)
at getConditionalTypeInstantiation (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42537:40)
at instantiateTypeWorker (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42620:24)
at instantiateType (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42575:26)
at /home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42274:42
at Object.map (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:507:29)
at getConditionalTypeInstantiation (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42537:40)
at instantiateTypeWorker (/home/anyhowstep/node-projects/tsql/tsql/node_modules/typescript/lib/typescript.js:42620:24)
However, if the code I wrote really was the problem, it shouldn't have run fine in 3.5.1. It should have also exceeded the max call stack size.
I don't have a minimal repro but I noticed something weird.
The following exceeds the constraint depth on 3.6 and 3.7,
However, the following does not,
Trying to nest function calls directly triggers the constraint depth error. But assigning it to a temporary variable is OK.
I'm a bit at a loss here and out of my depth (haha, depth).
- When was
constraintDepth
added? - Why was it added?
- What problem was it trying to solve?
Code that worked fine in TS 3.5.1 now hits this constraintDepth
error.
Removing the limit causes the max call stack size to be exceeded.
So, it looks to me like there's a bug with the code surrounding the constraintDepth
implementation. Hopefully, the answers to my questions can help me refactor my code to not hit the depth limit. Or maybe it'll expose a bug that needs fixing in the TS code base.