microsoft / microsoft/TypeScript
Discriminating property with never as possible type makes its enclosing object type disappear when narrowing
オープン
まだ誰も着手していません。
In Discussion
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
discriminated union never, discriminating property never
🕗 Version & Regression Information
It happens in every version I tried.
⏯ Playground Link
💻 Code
type DiscUnion =
| { discProp: never, a: 1 }
| { discProp: "prop", b: 2 }
| { discProp: undefined, c: 3 }
declare const o: DiscUnion
if(o.discProp) {
o
// ^? { discProp: "prop"; b: 2; }
} else {
o
// ^? { discProp: undefined; c: 3; }
}
if(!o.discProp) {
o
// ^? { discProp: undefined; c: 3; }
} else {
o
// ^? { discProp: "prop"; b: 2; }
}
🙁 Actual behavior
{ discProp: never, a: 1 } disappears!
🙂 Expected behavior
In the first if, I expect { discProp: never, a: 1 } to be a possible type of o in the else branch. Viceversa, in the second if I expect it to be a possible type of o in the then branch.
Additional information about the issue
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された TypeScript Playground の再現コードから始め、DiscUnion の例を記述どおりに実行します。if(o.discProp) と if(!o.discProp) の両方について絞り込みを追跡します。{ discProp: never, a: 1 } メンバーが期待される分岐で引き続き可能であり、他の絞り込まれたメンバーが変更されなければ作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100