Skip to content

Interfaces and classes considered equal #8168

@jrieken

Description

@jrieken

TypeScript Version:

1.8.0

Code

// A self-contained demonstration of the problem follows...
class A {
    constructor(a: number, b: boolean) {

    }
    foo() {

    }
    bar: boolean;
}

function doIt(a: A) {
    if (a instanceof A) {

    }
}

doIt(new A(1, true));

doIt({ foo() { }, bar: false }); // expect type check error

Expected behavior:

The second to doIt should raise a type check error.

Actual behavior:

It does not. I assume it was a conscious decision and I wonder why? This break assumptions the instanceof operator makes and has led to subtle bugs on our side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions