microsoft / microsoft/TypeScript
Crash: RangeError: Invalid string length in addSpans during instantiation of recursive template literal types
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
### 🔎 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
https://www.typescriptlang.org/zh/play/?target=7&ts=6.0.0-dev.20260319#code/C4TwDgpgBAIhDGAeAclCAPYEB2ATAzlNgK4C2ARhAE4B8UAvFAFBStSoZZ6ECsUA-FAAsUAFzs0mHAWECoAZjETO0wosEAmJSzYcp3KFsEBDbCG1tl+mQEY5ABiX2A3EyahIUAEoJiVFJJcMiQU1AA0UADKgapQ+MBUAJbYAOZ0jDqsekGEjoLR4j7wfohwSMg0EQAGACQA3pEAvgD69U1VNK7u4NAAouhgADYA9rjQjHWZUADaAApQyd6+-jwRAETGa3TGhLV1sy0A1hAgVQC64qYgro3OQA
### 💻 Code
```ts
type Dec =
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 0 ? S : Recur, `${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_
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Reproduisez le crash avec l’exemple récursif de template literal fourni ou avec la commande specializedSignatureIsNotSubtypeOfNonSpecializedSignature_filled_1_unvalidated_mutated_batch12.ts. Commencez par addSpans et getTemplateLiteralType dans built/local/tsc.js, en suivant la pile jusqu’à instantiateTypeWorker. C’est terminé lorsque le compilateur signale l’entrée ou la traite sans lever RangeError: Invalid string length.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100