microsoft / microsoft/TypeScript

Allow `export type Foo;` as valid syntax

Aperta
#30,932 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Search Terms

Exporting a type defined elsewhere. Export a defined type. Type alias circularly references itself. Can't export a type with the same name.

Suggestion

Currently you can only export types right when you declare them:

export type Foo = string | number;

But many people often use ambient files to make their types available globally throughout the project without the need to import them. This however means that the types cannot be exported directly where they define them because the file would cease to be ambient. The current way of coping with this is naming the type differently for internal use and then reexporting it with a different name:

// in types.ts
type _Foo = string | number;

// in index.ts
export type Foo = _Foo;

I suggest that this inconvenience could be easily solved by allowing this syntax:

export type Foo;

Use Cases

As described above, it's useful to export types defined in ambient files.

Examples

As above

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

Non vengono indicati file, test o punti di ingresso. Inizia tracciando come TypeScript analizza e verifica le dichiarazioni export type, quindi determina le modifiche necessarie al parser, al controllo dei tipi e ai test di regressione; il lavoro è completato quando la sintassi proposta viene accettata per i tipi ambient senza modificare l’output JavaScript.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
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.