microsoft / microsoft/TypeScript

Nullish coalescing operator but for conditional types

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

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

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

説明

🔍 Search Terms

nullish coalescing operator
conditional types

✅ Viability Checklist
⭐ Suggestion

Add syntactic sugar to allow this:

type T = A extends B ?? C

to be shorthand of:

type T = A extends B ? A : C
📃 Motivating Example

When working with large complicated types, it is often that you need to check that a type extends another type before passing it as a type argument to another type.

For example, ensuring it is an array before passing it to something that requires it to be an array:

type Foo<T> = Bar<
    Some<Really<Deep<Complex<Type<Utility<T>>>>>> extends readonly unknown[]
        ? Some<Really<Deep<Complex<Type<Utility<T>>>>>>
        : never
>;

type Bar<T extends readonly unknown[]> = ...;

The more complex the type you need to check, the more you need to repeat yourself to pass the same type in again.

This proposal aims to address that.

type Foo<T> = Bar<
    Some<Really<Deep<Complex<Type<Utility<T>>>>>> extends readonly unknown[] ?? never
>;
💻 Use Cases
  1. What do you want to use this for?

Making my type code more readable and easier to maintain.

  1. What shortcomings exist with current approaches?

The need to repeat yourself. Updates to the type need to be make in two places.

  1. What workarounds are you using in the meantime?

The long-form syntax.

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

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

はじめの一歩

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

調査の方向性

この issue では実装ファイルやテストが指定されていません。まず条件型がどのようにパースされ、チェックされるかを追跡し、次に A extends B ?? CA extends B ? A : C と同じように振る舞うために必要な構文および型システムの変更を判断してください。短縮記法が受け入れられ、示されている同等の型の振る舞いになることを完了条件とします。

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

評価

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

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

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