Closed
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?