microsoft / microsoft/TypeScript
Re-export module namespace as global
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
We're attempting to migrate users within Google to new @types typings, which move most typings into modules, and having a ton of trouble. The basic problem is that a module (e.g. CodeMirror) used to declare a global complex interface:
```
declare function CodeMirror(...);
declare namespace CodeMirror { ... }
```
and now they are modules:
```
export = CodeMirror;
```
and other typings refer to them as modules (so we can't just undo that export statement) but we also have tons of older user code that *doesn't* refer to them as modules. Ideally we'd be able to make it work both ways while we migrate users incrementally.
I appreciate that you don't want the language to make this convenient, but I'm having difficulty finding any way to make it work temporarily while we migrate.
Some things I tried:
1) Aliasing the module into the global namespace
```
declare global {
import CodeMirror = require('codemirror');
}
```
(and other variants) fails with "Imports are not permitted in module augmentations.".
2) Making the module global first, then aliasing it into a module namespace.
If you wrap the file contents with a "declare global {", then I couldn't figure out a way to repackage that global as a module again. The `export = CodeMirror;` fails with "Cannot find name 'CodeMirror'." despite the global CodeMirror being declared in the same file.
Do you have any advice? Note that "export as namespace" doesn't help because our user code is already modules, not scripts.
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 Deklarationsmustern und den in der Issue zitierten Diagnosen. Verfolge, wie `export =`, `declare global` und `export as namespace` behandelt werden, und ermittle anschließend, ob ein unterstützter Ansatz oder eine Sprachänderung sowohl die Modul- als auch die globale Verwendung erfüllen kann; als abgeschlossen gilt die Aufgabe erst, wenn eine klare, getestete Lösung vorliegt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100