microsoft / microsoft/TypeScript

export as namespace doesn't support nesting namespaces

Aperta
#20,990 5 commenti 14 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

I'm using rollup to generate a UMD module from my TypeScript source. It's part of a bigger product, so one component exports to a root namespace (e.g. mylib) and another exports to a namespace nested under that (e.g. mylib.plugins.myplugin). Rollup is generating the necessary UMD logic to walk down from the global scope creating namespaces as needed, but I can't model that in my TypeScript d.ts file.

The export as namespace syntax is working great in the first case, but not the second. It looks like TypeScript doesn't support nested namespaces for this purpose. Is this by design or just an omission?

TypeScript Version: 2.7.0-dev.20180103

Code: Two files, a d.ts containing an export as namespace foo.bar declaration and a script that references it.

declaration.d.ts

export var baz;

export as namespace foo.bar;

app.ts

console.log(foo.bar.baz);

Compile with: tsc .\test.d.ts .\main.ts

Expected behavior: The file compiles correctly to the following JS:

console.log(foo.bar.baz);

Actual behavior: Error

declaration.d.ts(3,24): error TS1005: ';' expected.

If I change declaration.d.ts to use export as namespace foo (and update app.ts as needed), the compilation succeeds.

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 la riproduzione minima di declaration.d.ts e app.ts, quindi esegui tsc .\test.d.ts .\main.ts per confermare l’errore TS1005 per export as namespace foo.bar. Traccia come viene analizzato e validato export as namespace; il lavoro è completato quando i namespace annidati vengono compilati e mantengono l’uso previsto di foo.bar.baz.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.