microsoft / microsoft/TypeScript

NoInfer breaks discriminate union autocomplete

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

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

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

説明

🔎 Search Terms

no infer discriminate union

🕗 Version & Regression Information

Tested on version 5.6.3

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgILIN4ChnLATwAcIAuZAcjnIBodkA3OAGwFdTkBnMKUAcwG4sAXyxZQkWIhQAhTHQLEy5AEY06HYAC92IFgFtl0QSKwKUAVRDAA9iGQBeNMgA+yaYKwwWIBGBt3EJEIwAB4AFWQIAA9IEAATDmRLfwA+AApvfzIAOWsASRAYaHCUgEo5YVFAiGC0jDMlKiFSoA

💻 Code
interface A {
  type: 'a',
  value: string;
}

interface B {
  type: 'b',
  size: number;
}

type Union = A | B;

function accept<T extends Union>(union: NoInfer<T>) {

}

accept({type: 'a'})
🙁 Actual behavior

When trying to autocomplete after writing type a the autocomplete doesn't work (but the result does get type checked):
Image

🙂 Expected behavior

Even with NoInfer it should autocomplete the other properties of the "inferred" discriminate union case as it correctly type checks it if written wrong.

Additional information about the issue

No response

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

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

はじめの一歩

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

調査の方向性

リンクされている TypeScript Playground の再現から始め、NoInfer と判別可能なユニオンに対する既存の型チェック結果とオートコンプリートの動作を比較してください。type 'a' を入力した後に、選択されたユニオンケースの残りのプロパティが提示され、誤った値が引き続き拒否されれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

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

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