microsoft / microsoft/TypeScript

Wildcard/star export from type expression

オープン
#59,758 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔍 Search Terms
  • "export ="
  • "export type ="
  • flatten type export
  • export top-level type
  • wildcard export type
  • star export type
  • "export *"
  • "export type *"
✅ Viability Checklist
⭐ Suggestion

Introduce syntax for exporting a "spread" type:

// 1. This is based on ES export lists and spread tuple types. It would only be
//    valid for types, since modules have to be statically analyzable:
export { ...ComplexType };
export type { ...ComplexType };

// 2. Not currently valid in normal type expressions, so might be
//    unexpected, even if it mirrors valid ES syntax. However, it might be
//    something to consider allowing independently, since it's not quite the
//    same as an intersection type, and would be useful for "overwriting"
//    properties:
type Spread = { ...ComplexType };
//              ^ Member 'Complex' implicitly has an 'any' type. (7008)

// 3. These are probably too "generic" and easy to confuse with other export
//    syntax, and doesn't make the required "object" shape obvious:
export ComplexType;          // spread
export type ComplexType;     // spread
export type Other = boolean; // NOT spread

// 4. Barrel export syntax would be a bit more explicit, and mirrors their
//    respective import syntax nicely:
import type * as ComplexType from "./a.ts";
export type * from ComplexType;       // inverse of the import
export type { Foo } from ComplexType; // also potentially nice to have

// 5. An alternative based on CommonJS top-level export syntax, but probably
//    undesirable to use for ES modules:
export = { Foo: "a", Bar: 1 }; // top-level value
export type = ComplexType;     // top-level ("spread") type

I'd personally prefer (4), but if extending spreading to object types is feasible, (1) would also be a natural choice.

📃 Motivating Example

Not having "spreadable" type exports requires a lot of repetition in cases like this one, which this feature would alleviate significantly:

export type ComplexType = {
   Foo: string,
   Bar: number,
};

// A. This is how it works right now. Every type name has to be repeated three
//    times each:
export type Foo = ComplexType["Foo"];
export type Bar = ComplexType["Bar"];
export { Foo, Bar };

// B. This is what you could do instead:
export type * from ComplexType; // (4)
export type { ...ComplexType }; // (1)

// C. You could even trivially allow mapped/filtered exports
export type * from {  [K in keyof ComplexType]: K extends 'Bar' ? never : ComplexType[K]; }; // (4)
export type { [K in keyof ComplexType]: K extends 'Bar' ? never : ComplexType[K]; };         // (1)
💻 Use Cases

See Motivating Example

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ファイル、テスト、エントリーポイントのいずれも指定されていません。まず提案されている構文の代替案を確認し、関連する TypeScript の export と型チェックのパスを特定してください。完了とするには、設計の確定、実装、回帰カバレッジが必要ですが、この issue ではどの代替案を実装するかは選択されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。