microsoft / microsoft/TypeScript
@ts-ignore on an import that gets redefined strips the import from output
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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();
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Verhalten aus dem bereitgestellten TypeScript-3.7.5/3.8.0-Code und dem Playground-Link und verfolge anschließend die Entscheidung des Compilers zur Import-Eliminierung für einen Import, auf den eine Neudeklaration folgt. Als erledigt gilt die Aufgabe, wenn das ausgegebene JavaScript den Import wie in der erwarteten Ausgabe beibehält und dieser Fall durch Tests abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100