Skip to content

instanceof doesn't work if Function interface changes #1228

Closed
@rjamesnw

Description

@rjamesnw

Extending the Function interface should not cause "instanceof" to fail. Adding new items shouldn't change the fact that it's still a Function instance type. (see http://goo.gl/mCb93P)

interface Function {
    [index: string]: any;
}

class Base { }
class Greeter extends Base {
    greeting: string;
    constructor(message: string) {
        super();
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}

var greeter = new Greeter("world");

var button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function () {
    alert(greeter.greet());
}

document.body.appendChild(button);

var b: Base;
(b instanceof Greeter); <== 'Greeter' is an ERROR

The whole error message is "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."

The expected behaviour is that anything that is of type Function would inherit this same change, and thus should not cause errors.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptBy DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions