microsoft / microsoft/TypeScript

export default type

Offen
#41,409 7 Kommentare 48 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

export default type

Suggestion

Allow export default for type.

Use Cases

It would be very nice to have export default type to match with other default exports such as classes and interfaces.

Right now it looks very inconsistent to be able to export anything as default and only types with named export:

export default class MyClass {}
export default interface MyInterface {}
export type MyType = {}

The only way to achieve this now is to use annoying workaround:

type X = number | string

export { X as default }

This may cause confusion for newbies as there are no clear reasons why classes and interfaces can be exported as default, but not the types.

Examples

// x.ts
export default type X = {}

// main.ts
import X from './x'

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.

(not sure on the last)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Der Issue enthält Syntaxbeispiele zum Hinzufügen von Default-Exports zu Typen, nennt aber keine Quelldateien, Tests oder Einstiegspunkte. Beginne damit, die bestehende Behandlung von Default-Exports für Klassen und Interfaces nachzuverfolgen, und ermittle dann, für welches Verhalten von parser, checker und emit eine Abdeckung erforderlich wäre; als abgeschlossen gilt die Arbeit, wenn die vorgeschlagene Syntax mit dem gezeigten Import funktioniert, ohne das emittierte JavaScript 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
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.