microsoft / microsoft/TypeScript
allowJs option with namespaces
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
I am currently trying to put the compiler option "allowJs" to use. My goal is to convert an existing JavaScript application into TypeScript step by step. The application does not use (external) modules, so I'm converting the JavaScript namespaces into real TypeScript namespaces, but I'm running into "duplicate identifier" errors as outlined below. Shouldn't it be possible to combine TypeScript and JavaScript using the same namespace? Maybe I'm doing something wrong or this is not intended, but I expected this to work.
TypeScript Version: 1.8.10
Code
File 1:
namespace myapp {
export var c1 = 5;
}
File 2:
var myapp;
(function (myapp) {
myapp.c2 = 4;
})(myapp || (myapp = {}));
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"outFile": "dist/appBundle.js"
}
}
Expected behavior:
Bundling the compiled code of file 1 and the code of file 2 without modifications into a single JavaScript file.
Actual behavior:
The compilation is done, but the compiler throws an error: "error TS2300: Duplicate identifier 'myapp'."
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
Beginne mit den beiden Beispieldateien und der bereitgestellten tsconfig.json unter Verwendung von TypeScript 1.8.10 und reproduziere dann den TS2300-Fehler wegen doppelter Bezeichner mit allowJs, namespaces und outFile. Als erledigt gilt, wenn der TypeScript- und der JavaScript-Code für namespaces ohne Änderung des JavaScript-Codes oder Meldung des doppelten Bezeichners in eine einzige JavaScript-Datei gebündelt werden kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100