microsoft / microsoft/TypeScript

5.8.3 - Big repo with complex types in Angular - Maximum call stack size exceeded

Aperta
#62,415 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs More Info
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

🔎 Search Terms

max call stack size

🕗 Version & Regression Information
  • I was unable to test this on prior versions because of custom code on our end
⏯ Playground Link

No response

💻 Code

We use a custom version of TypeScript, here are our changes, all the changes are similar, we just changed the values and the version of TS to publish it on our Azure DevOps

src/compiler/checker.ts

...
19126    if (tailCount === 5e4) {
...
20365    if (instantiationDepth === 5e3 || instantiationCount >= 5e8) {
...

lib/_tsc.js

...
61663    if (tailCount === 5e4) {
...
62704    if (instantiationDepth === 5e3 || instantiationCount >= 5e8) {
...

lib/typescript.js

...
66273    if (tailCount === 5e4) {
...
67314    if (instantiationDepth === 5e3 || instantiationCount >= 5e8) {
...

As for our repository I could share it somewhere under some NDA because the error depends probably on the size and the complexity of the types.

🙁 Actual behavior
RangeError: Maximum call stack size exceeded
      at ...\node_modules\typescript\lib\typescript.js:72137:242
      at map (...\node_modules\typescript\lib\typescript.js:2491:19)
      at inferTypesFromTemplateLiteralType (...\node_modules\typescript\lib\typescript.js:72137:224)
      at inferToTemplateLiteralType (...\node_modules\typescript\lib\typescript.js:72590:23)
      at inferFromTypes (...\node_modules\typescript\lib\typescript.js:72364:9)
      at inferTypes (...\node_modules\typescript\lib\typescript.js:72209:5)
      at structuredTypeRelatedToWorker (...\node_modules\typescript\lib\typescript.js:69945:13)
      at structuredTypeRelatedTo (...\node_modules\typescript\lib\typescript.js:69474:21)
      at recursiveTypeRelatedTo (...\node_modules\typescript\lib\typescript.js:69425:19)
      at isRelatedTo (...\node_modules\typescript\lib\typescript.js:68843:122)
🙂 Expected behavior

All this used to work with 5.4.5 but it does not with 5.8.3

Additional information about the issue

We always had problems with complex types in TypeScript in our project which is pretty big (which also makes us question if it is really suited for bigger projects...).
We have experienced a lot of Type instantiation is excessively deep and possibly infinite errors and it's not clear which types cause them or how to solve the issue.
So we resolved to "hacking" TypeScript by using a custom version of 5.4.5 where we bumped up the values of tailCount, instantiationDepth and instantiationCount to fit our needs and everything was working with Angular 17 and 18, when we tried upgrading to Angular 19 with TypeScript 5.8.3 "hacked" we get the Error above.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Il report indica src/compiler/checker.ts e i file generati lib/typescript.js e lib/_tsc.js, con lo stack che entra in inferTypesFromTemplateLiteralType e nelle relative funzioni di inferenza. Per prima cosa riduci il caso del repository privato di Angular a una riproduzione pubblica e confronta TypeScript 5.4.5 con 5.8.3. Il lavoro è completato quando la riproduzione non causa più un errore di profondità massima dello stack delle chiamate, mantenendo al contempo il comportamento previsto del controllo dei tipi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.