Evolving array element type ignores contextual type#15075
Conversation
Control flow analysis can easily hit circularities or exponential behaviour when requesting the contextual type of an expression. When adding an element type to an evolving array type, there is no point in checking the contextual type of the new element type because it is unknown -- it is exactly the type of the evolving array, which is in the middle of being found. Fixes #14628 This is code of the form: ```ts let x = [] x[0] = { contextual: 'no' } x[1] = { contextual: 'should not check' } x[2] = { contextual: 'contextual type' } // : // : ```
Previously, the compiler would run out of memory for more than 13 or 14 of these assignments.
|
Please release this fix for 2.3.x, this is breaking most of my projects. It was not released with 2.3.1, I'm forced to use |
|
this fix specifically made it to release 2.3.1 and 2.3.2. if that is not working for you then there is a different issue here that we need to investigate. |
|
I'm running into exactly this problem on 2.3.2. The VS Code language service works fine, webpack (with awesome-typescript-loader) crashes. Our code is proprietaty but I'll happily share it privately with a TypeScript team member if that helps. Email me at egbert@talkjs.com if this is an option. |
does it fail with |
Control flow analysis can easily hit circularities or exponential behaviour when requesting the contextual type of an expression. When adding an element type to an evolving array type, there is no point in checking the contextual type of the new element type because it is unknown -- it is exactly the type of the evolving array, which is in the middle of being found.
Fixes #14628
This is code of the form:
I considered adding a third parameter to
getTypeOfExpressionand callingcheckExpressionWithContextualType, but I decided having a new function that delegates togetTypeOfExpressionis less confusing.