microsoft / microsoft/TypeScript
Crash: RangeError: Invalid string length in addSpans during instantiation of recursive template literal types
オープン
まだ誰も着手していません。
Bug
Domain: Crashes
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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