microsoft / microsoft/TypeScript

Crash: RangeError: Maximum call stack size exceeded in getNameOfSymbolAsWritten via recursive conditional ReturnType

未关闭
#63,273 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Bug Domain: check: Type Circularity
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 Search Terms

RangeError: Maximum call stack size exceeded

getNameOfSymbolAsWritten crash

symbolToTypeNode recursion

ReturnType indexed access crash

### 🕗 Version & Regression Information

Versions tested: 5.7.3, 5.8.3, 5.9.3, Nightly, TS7.

### ⏯ Playground Link

https://www.typescriptlang.org/zh/play/?target=7&ts=6.0.0-dev.20260319#code/GYVwdgxgLglg9mABBANggpgCgJQC5EA8AKgHyZwBGAVvkdogLwmJGLoAeU6YAJgM6IAhmACeiAPyIASuiggATmCIiADugJRV6OMGRow6EgG0ADAF1E+EwG4gA

### 💻 Code

```ts
function clone(): (obj: T) => T extends any ? ReturnType[0] : 0;
```

### 🙁 Actual behavior

```
node built/local/tsc.js -noEmit functionOnlyHasThrow_filled_2_unvalidated_mutated_batch6.ts
D:\github\TypeScript\built\local\_tsc.js:123721
throw e;
^

RangeError: Maximum call stack size exceeded
at getTextOfNodeFromSourceText (D:\github\TypeScript\built\local\_tsc.js:13034:37)
at getSourceTextOfNodeFromSourceFile (D:\github\TypeScript\built\local\_tsc.js:13017:10)
at getTextOfNode (D:\github\TypeScript\built\local\_tsc.js:13045:10)
at declarationNameToString (D:\github\TypeScript\built\local\_tsc.js:13854:60)
at getNameOfSymbolAsWritten (D:\github\TypeScript\built\local\_tsc.js:55596:16)
at createAccessFromSymbolChain (D:\github\TypeScript\built\local\_tsc.js:53234:25)
at symbolToTypeNode (D:\github\TypeScript\built\local\_tsc.js:53211:26)
at typeToTypeNodeWorker (D:\github\TypeScript\built\local\_tsc.js:51561:18)
at typeToTypeNodeHelper (D:\github\TypeScript\built\local\_tsc.js:51342:24)
at conditionalTypeToTypeNode (D:\github\TypeScript\built\local\_tsc.js:51640:31)

Node.js v22.19.0
```

### 🙂 Expected behavior

The compiler should not crash.

### Additional information about the issue

_No response_

贡献指南

打开贡献指南

调研方向

使用链接的 Playground 示例,或针对 functionOnlyHasThrow_filled_2_unvalidated_mutated_batch6.ts 运行报告中的 tsc 命令,重现该崩溃。跟踪报告中的路径,依次经过 conditionalTypeToTypeNode、typeToTypeNodeWorker、symbolToTypeNode 和 getNameOfSymbolAsWritten,然后添加一个回归测试,展示此递归 ReturnType 案例可以在不发生崩溃的情况下完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。