Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instanceof in type guards should not narrow any #1426

Closed
JsonFreeman opened this issue Dec 10, 2014 · 2 comments · Fixed by #1433
Closed

Instanceof in type guards should not narrow any #1426

JsonFreeman opened this issue Dec 10, 2014 · 2 comments · Fixed by #1433
Assignees
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification

Comments

@JsonFreeman
Copy link
Contributor

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
}
@JsonFreeman JsonFreeman added Bug A bug in TypeScript Breaking Change Would introduce errors in existing code Spec Issues related to the TypeScript language specification labels Dec 10, 2014
@JsonFreeman
Copy link
Contributor Author

This broke a customer. Before type guards it was working.

@basarat
Copy link
Contributor

basarat commented Feb 5, 2015

any is evil

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants