Skip to content

instanceof type guard does not narrow type of this #5534

Description

Here's an example which demonstrates (tested on 1.6.2 and current playground):

classFoo{a: number;foo(): string{if(thisinstanceofBar){returnthis.b;// not okay - `this` typed as Foo}return'';}bar(): string{letthat=this;if(thatinstanceofBar){returnthat.b;// okay - `that` typed as Bar}return''}}classBarextendsFoo{b: string;}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions