microsoft / microsoft/TypeScript

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

Open
#63,273 1 comment 0 reactions 0 assignees View on GitHub
Bug Domain: check: Type Circularity
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 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_

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the linked Playground example or by running the reported tsc command against functionOnlyHasThrow_filled_2_unvalidated_mutated_batch6.ts. Trace the reported path through conditionalTypeToTypeNode, typeToTypeNodeWorker, symbolToTypeNode, and getNameOfSymbolAsWritten, then add a regression test showing that this recursive ReturnType case completes without crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.