microsoft / microsoft/TypeScript
Allow `export type Foo;` as valid syntax
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
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.
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
Es werden keine Dateien, Tests oder Einstiegspunkte genannt. Beginne damit nachzuverfolgen, wie TypeScript Deklarationen von export type parst und prüft, und ermittle dann die erforderlichen Änderungen am Parser, an der Typprüfung und an den Regressionstests; abgeschlossen ist die Arbeit, wenn die vorgeschlagene Syntax für Ambient-Typen akzeptiert wird, ohne die JavaScript-Ausgabe zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 25/100