microsoft / microsoft/TypeScript

tsc and tsserver have different ideas of excessively deep types

Aperta
#32,573 10 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

TypeScript Version:

typescript-3.6.0-insiders.20190725

https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/37759/artifacts?artifactName=tgz&fileId=2A7E3F3E93DD6F833D63A63F3A7A21707B3F57B08FCA5C93A8F1848556D8141F02&fileName=/typescript-3.6.0-insiders.20190725.tgz

Taken from,
https://github.com/microsoft/TypeScript/pull/32028#issuecomment-515234327

Search Terms:

max instantiation count, max instantiation depth, tsc, tsserver

Code

I've reduced the 40-subproject monorepo to just small parts of 2 subprojects.

Here is a snippet of the problem,


/**
 *
 * ```json
 * //tsconfig-base.json
 * "disableSourceOfProjectReferenceRedirect": true,
 * ```
 *
 * ```json
 * //package.json
 * "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/37759/artifacts?artifactName=tgz&fileId=2A7E3F3E93DD6F833D63A63F3A7A21707B3F57B08FCA5C93A8F1848556D8141F02&fileName=/typescript-3.6.0-insiders.20190725.tgz"
 * ```
 *
 * -----
 *
 * VS Code: OK!
 * Type inference OK!
 *
 * -----
 *
 * `tsc` gives me,
 *
 * ```js
 * src/blah.ts:11:21 - error TS2589: Type instantiation is excessively deep and possibly infinite.
 *
 *  11 export const json = tm.deepMerge(
 *                         ~~~~~~~~~~~~~
 *  12     base.json,
 *     ~~~~~~~~~~~~~~
 * ...
 *  31     s.convertBlahType.toStr.BLAH
 *     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  32 );
 *     ~
 * ```
 */
export const json = tm.deepMerge(
  /*snip*/
);

const x = json("", "");
if (x.foo != undefined) {
    if (x.foo.bar != undefined) {
        //Correctly infers `string`
        //So, 14M type instantiations is okay with VS code
        x.foo.bar.baz
    }
}

Expected behavior:

If tsc gets the error,

TS2589: Type instantiation is excessively deep and possibly infinite.

Then tsserver should also get the error

Actual behavior:

tsc gets the error, but tsserver does not (or at least VS code infers the type correctly without errors)

Playground Link:

-None-

@sheetalkamat

The project involved contains code related to a company project.
So, I really do not want to upload it publicly, if possible.

I could mangle the variable names so that they're meaningless but if I can just email the parts of the project that are involved, that would be nice.

Repro steps:

  1. npm install
  2. npm run build
  3. See TS2589: Type instantiation is excessively deep and possibly infinite.
  4. Open VS code
  5. Navigate to file tsc says contains errors
  6. Notice no errors
  7. Play with return type of function
  8. Notice inference works correctly

Related Issues:

The merged PR that introduced the error,
https://github.com/microsoft/TypeScript/pull/32079#issuecomment-515334873

The build I am testing,
https://github.com/microsoft/TypeScript/pull/32028

Also relevant, https://github.com/microsoft/TypeScript/issues/29511
It seems like every few versions, there ends up being a difference between tsc and tsserver, regarding the max instantiation depth

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

Inizia con i passaggi di riproduzione forniti per npm install/build e VS Code, quindi confronta le diagnosi di tsc e tsserver. Leggi il comportamento descritto in PR 32079 e nella issue correlata 29511; il lavoro è completo quando entrambi gli strumenti segnalano in modo coerente l'errore di tipo «excessively deep» per lo stesso progetto.

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

Valutazione

Stack tecnologico
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
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.