Spec contradicts to itself in one of the examples with type guards #1808
Copy link
Copy link
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?
Reactions are currently unavailable
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

Activity
ahejlsberg commentedon Jan 26, 2015
Yes, that is a bug in the spec.