microsoft / microsoft/TypeScript
Better printing of `T & U` where this is equivalent to `Extract<T, U>`
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Suggestion
🔍 Search Terms
Extract intersection union ide editor printing
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
There are many cases where T & U is equivalent to Extract<T, U>. However, the former has much worse type printing in these cases than the latter, leading to a much worse developer experience for this case.
I initially raised this as an eslint rule, but it would be very difficult to do do from that side (as explained in the comments of https://github.com/typescript-eslint/typescript-eslint/issues/2983
📃 Motivating Example
type A = Action & { type: 'action1' | 'action2' }
// ({
// type: 'action1';
// a: number;
// } & {
// type: 'action1' | 'action2';
// }) | ({
// type: 'action2';
// b: string;
// } & {
// type: 'action1' | 'action2';
// })
type B = Extract<Action, { type: 'action1' | 'action2' }>
// {
// type: 'action1';
// a: number;
// } | {
// type: 'action2';
// b: string;
// }
💻 Use Cases
Improve developer experience, error messages, and IDE support.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
動機となる TypeScript の例と、リンクされている TypeScript Playground の再現から始めてください。型の出力と IDE サポートに関わる挙動を調査してください。完了条件は、実行時の挙動を変更せずに、同値な交差型がより明確な Extract-like 形式で提示されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- developer-experience
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100