Skip to content

Typeguard fails in function after instanceof #10273

Closed
@hpop

Description

@hpop

TypeScript Version: nightly (2.0.0-dev.201xxxxx)

Code

class A {
  foo = 'hello';
}

class B extends A {
  bar = 'hello';
}

let a:A = new B();

if (a instanceof B) {
  console.log(a.bar); // working
}

if (a instanceof B) {
  setTimeout( () => {
    console.log(a.bar); // error
  });
}

Expected behavior:
TypeScript should recognize a as instance of B. This worked in 1.8

Actual behavior:
test.ts(17,17): error TS2339: Property 'bar' does not exist on type 'A'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions