-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
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:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone