microsoft / microsoft/TypeScript

Allow type-only named re-exports along with assigned export in the same file

Aperta
#38,866 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Search Terms

allow export types assigned =

Suggestion

The suggestion is to allow compilation of files that do both export = and export type {}.

Use Cases

For modules that target both TypeScript and CommonJS usage it would allow consolidating all exports for both module systems in one file (albeit with the requirement of esModuleInterop being true).

Currently, in order to do that I would have to utilize @ts-ignore (see parzh/xrange#69 for details).

Examples

/person.ts:

import personValue from "./person-value";

export = personValue;

export type { default as PersonType } from "./person-type";

/person-type.ts:

export default interface Person { name: string; }

/person-value.ts:

export default { name: "John Doe" } as import("./person-type").default;
Usage:

/usage.ts:

import personValue from "./person";
import personValue, { PersonType } from "./person";
import type { PersonType } from "./person";
import personValue = require("./person");

/usage.js:

const personValue = require("./person");

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

La issue nomina i file di esempio person.ts, person-type.ts, person-value.ts e usage.ts, ma non indica file del compilatore né test. Inizia individuando come il compilatore gestisce export = insieme alle esportazioni nominate di soli tipi, quindi verifica che l'esempio venga compilato e che le esportazioni di soli tipi non modifichino il JavaScript emesso.

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
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.