-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification
Milestone
Description
In the section about type guards, the last example seems to be invalid:
class NamedItem {
name: string;
}
function getName(obj: any) {
return obj instanceof NamedItem ? obj.name : "unknown";
}
It is stated that the inferred type of the 'getName' function is string
, but actually 'any' type won't be narrowed, according to the same spec, and compiler doesn't do that either:
A bug in the spec?
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification