Skip to content

Instanceof in type guards should not narrow any #1426

Closed
@JsonFreeman

Description

@JsonFreeman

Usually narrowing a type causes us to have access to more properties. Not so if the original type was any. In this case, narrowing actually causes us to lose properties. So we should not get an error in the following case:

var x: any = { p: 0 };
if (x instanceof Object) {
    x.p; // Error that p does not exist on Object
}

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFixedA PR has been merged for this issueSpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions