microsoft / microsoft/TypeScript
Crash: RangeError: Invalid string length in addSpans during instantiation of recursive template literal types
未关闭
还没有人认领这个 Issue。
Bug
Domain: Crashes
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
🔎 Search Terms
RangeError: Invalid string length
addSpans crash
getTemplateLiteralType recursion
Template literal exponential growth
🕗 Version & Regression Information
Crashes in: 5.7.3, 5.8.3, 5.9.3, Nightly.
⏯ Playground Link
💻 Code
type Dec<N extends number> =
N extends 5 ? 4 : N extends 4 ? 3 : N extends 3 ? 2 :
N extends 2 ? any :
N extends 1 ? 0 : 0;
type Recur<N extends number, S extends string> =
N extends 0 ? S : Recur<Dec<N>, `${S}_${S}`>;
type Explode = {
[P in Recur<5, "a"> as `${P}_key`]: any;
};
🙁 Actual behavior
node built/local/tsc.js -noEmit specializedSignatureIsNotSubtypeOfNonSpecializedSignature_filled_1_unvalidated_mutated_batch12.ts
D:\github\TypeScript\built\local\_tsc.js:123721
throw e;
^
RangeError: Invalid string length
at addSpans (D:\github\TypeScript\built\local\_tsc.js:62120:19)
at getTemplateLiteralType (D:\github\TypeScript\built\local\_tsc.js:62095:10)
at instantiateTypeWorker (D:\github\TypeScript\built\local\_tsc.js:63780:14)
at instantiateTypeWithAlias (D:\github\TypeScript\built\local\_tsc.js:63736:20)
at instantiateType (D:\github\TypeScript\built\local\_tsc.js:63703:29)
at getMappedType (D:\github\TypeScript\built\local\_tsc.js:63383:67)
at D:\github\TypeScript\built\local\_tsc.js:62756:73
at map (D:\github\TypeScript\built\local\_tsc.js:196:19)
at canTailRecurse (D:\github\TypeScript\built\local\_tsc.js:62756:33)
at getConditionalType (D:\github\TypeScript\built\local\_tsc.js:62723:17)
Node.js v22.19.0
🙂 Expected behavior
The compiler should not crash.
Additional information about the issue
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用提供的递归模板字面量示例或 specializedSignatureIsNotSubtypeOfNonSpecializedSignature_filled_1_unvalidated_mutated_batch12.ts 命令重现崩溃。从 built/local/tsc.js 中的 addSpans 和 getTemplateLiteralType 开始,沿着堆栈跟踪到 instantiateTypeWorker。完成的标准是编译器报告或处理该输入,而不会抛出 RangeError: Invalid string length。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100