microsoft / microsoft/TypeScript
5.8.3 - Big repo with complex types in Angular - Maximum call stack size exceeded
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
max call stack size
### 🕗 Version & Regression Information
- I was unable to test this on prior versions because of custom code on our end
### ⏯ Playground Link
_No response_
### 💻 Code
We use a custom version of TypeScript, here are our changes, all the changes are similar, we just changed the values and the version of TS to publish it on our Azure DevOps
src/compiler/checker.ts
```ts
...
19126 if (tailCount === 5e4) {
...
20365 if (instantiationDepth === 5e3 || instantiationCount >= 5e8) {
...
```
lib/_tsc.js
```js
...
61663 if (tailCount === 5e4) {
...
62704 if (instantiationDepth === 5e3 || instantiationCount >= 5e8) {
...
```
lib/typescript.js
```js
...
66273 if (tailCount === 5e4) {
...
67314 if (instantiationDepth === 5e3 || instantiationCount >= 5e8) {
...
```
As for our repository I could share it somewhere under some NDA because the error depends probably on the size and the complexity of the types.
### 🙁 Actual behavior
```
RangeError: Maximum call stack size exceeded
at ...\node_modules\typescript\lib\typescript.js:72137:242
at map (...\node_modules\typescript\lib\typescript.js:2491:19)
at inferTypesFromTemplateLiteralType (...\node_modules\typescript\lib\typescript.js:72137:224)
at inferToTemplateLiteralType (...\node_modules\typescript\lib\typescript.js:72590:23)
at inferFromTypes (...\node_modules\typescript\lib\typescript.js:72364:9)
at inferTypes (...\node_modules\typescript\lib\typescript.js:72209:5)
at structuredTypeRelatedToWorker (...\node_modules\typescript\lib\typescript.js:69945:13)
at structuredTypeRelatedTo (...\node_modules\typescript\lib\typescript.js:69474:21)
at recursiveTypeRelatedTo (...\node_modules\typescript\lib\typescript.js:69425:19)
at isRelatedTo (...\node_modules\typescript\lib\typescript.js:68843:122)
```
### 🙂 Expected behavior
All this used to work with 5.4.5 but it does not with 5.8.3
### Additional information about the issue
We always had problems with complex types in TypeScript in our project which is pretty big (which also makes us question if it is really suited for bigger projects...).
We have experienced a lot of `Type instantiation is excessively deep and possibly infinite` errors and it's not clear which types cause them or how to solve the issue.
So we resolved to "hacking" TypeScript by using a custom version of 5.4.5 where we bumped up the values of `tailCount`, `instantiationDepth` and `instantiationCount` to fit our needs and everything was working with Angular 17 and 18, when we tried upgrading to Angular 19 with TypeScript 5.8.3 "hacked" we get the Error above.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
报告指向 src/compiler/checker.ts 以及生成的 lib/typescript.js 和 lib/_tsc.js,堆栈进入了 inferTypesFromTemplateLiteralType 及相关的推断函数。首先将私有 Angular repository 中的案例缩减为公开复现,并比较 TypeScript 5.4.5 与 5.8.3。当复现不再导致最大调用栈错误,同时保留预期的类型检查行为时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 20/100