microsoft / microsoft/TypeScript
'instanceof' changes type outside of 'if' statement
オープン
@orta がすでに取り組んでいます。
2019年6月12日 から。
Bug
Domain: check: Control Flow
Rescheduled
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.4.*
Search Terms:
instanceof
Code
// @strictNullChecks: true
interface OnChanges {
onChanges(changes: Record<string, unknown>): void
}
interface Validator {
validate(): null | Record<string, unknown>;
}
class C {
validate() {
return {}
}
}
function foo() {
let v: Validator & Partial<OnChanges> = null as any;
if (v instanceof C) {
}
if (v.onChanges) { // error here
v.onChanges({});
}
}
Expected behavior:
No error.
Actual behavior:
Property 'onChanges' does not exist on type 'C | (Validator & Partial<OnChanges>)'.
Property 'onChanges' does not exist on type 'C'.
instanceof shouldn't change the type of the variable outside of the if statement.
This only happens with strictNullChecks enabled.
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。