microsoft / microsoft/TypeScript
Conjunction of two disjunctions cause incorrect errors
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.3
Search Terms:
- Conjunction
Code
interface Small {
small: true,
callbackWhenSmallIsFalsy?: undefined;
}
interface NotSmall {
small?: false;
callbackWhenSmallIsFalsy: () => void;
}
interface Green {
green?: false
numberWhenGreenTrue?: undefined
}
interface NotGreen {
green: true
numberWhenGreenTrue: number;
}
type SmallProps = Small | NotSmall;
type GreenProps = Green | NotGreen;
type Props = SmallProps & GreenProps;
const try1: Props = {
green: true,
numberWhenGreenTrue: 5,
small: true
} // OK
const try2: Props = {
green: false,
numberWhenGreenTrue: 5,
small: true
} // Unexpected Error: 'callbackWhenSmallIsFalsy' is missing...
// Expected Error: 5 is not assignable to undefined for 'numberWhenGreenTrue'
const try3: Props = {
green: false,
small: true
} // OK
const try4: Props = {
green: false,
small: true,
callbackWhenSmallIsFalsy: () => 5
} // Acceptable Error: Types of property 'small' are incompatible.
// TS can't know which of the conditions to use, so this is okay. NTH: It lists multiple possible errors
Expected behavior:
in try3 I don't expect the error to be about callbackWhenSmallIsFalsy. I would expect an error about green or numberWhenGreenTrue
Actual behavior:
When the conjunction is evaluated as false, it appears that the compiler tries to force an error into the first part of the conjunction, when the falsehood is from the second part of the conjunction.
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、TypeScript Playground で issue の conjunction の例、特に try2 と try3 を再現し、コンパイラーの型チェックと診断の挙動を調べます。try2 のエラーが callbackWhenSmallIsFalsy ではなく numberWhenGreenTrue または green を指し、その他の表示されたケースが期待どおりの挙動を維持していれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100