microsoft / microsoft/TypeScript

@ts-ignore on an import that gets redefined strips the import from output

Aperta
#37,047 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JS Emit
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

TypeScript Version: 3.7.5 and 3.8.0

Search Terms:

  • ts-ignore remove import
  • ts-ignore strip import

Code

// @ts-ignore: Local Foo override
import Foo from "foo";

declare const Foo: {
    bar(): number;
}

Foo.bar();

Expected behavior:

JS output should probably be:

import Foo from "foo";

Foo.bar();

Actual behavior:

JS output is:

Foo.bar();

Playground Link: https://www.typescriptlang.org/play/index.html?ts=3.8-Beta&ssl=9&ssc=1&pln=1&pc=1#code/PTAEAEBcGcFoEsDmA7A9gJwKYC5QBlUBjAQwBtQAxVVUVAN03XXgBNMAoeAWwAcNJK1UADN0qLqABEw6pIDc7dm0KliWUIVTJoAqqlwBvdqBOgARmoAUASlzIArlzOMFAX0V6AdBfQ2FQA

Related Issues: None so far


Additional remarks: We are aware of other ways to type the foo module but in this particular case the foo override needs to be done in the file using it. As far as we tried, adding a ts-ignore is the only way to make ts understand that we want to redefine the module.
Now, this seems to move the declaration site from the import to the the declare statement and that has the effect to mark the import site as unused, since the import is unused, ts strips it.

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

Riproduci il comportamento del codice TypeScript 3.7.5/3.8.0 fornito e del link al Playground, quindi traccia la decisione del compilatore sull'eliminazione degli import per un import seguito da una ridichiarazione. Il lavoro è completo quando il JavaScript emesso mantiene l'import come mostrato nell'output previsto e questo caso è coperto dai test.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.