Skip to content

Property does not exist on type '(Anonymous class)' #14860

Closed

Description

@nickelya

TypeScript Version:
Version 2.2.1
Version 2.3.0-dev.20170325

Code

while (0);

new class {
    methodA() {
        this;
    }
};

new class {
    methodB() {
        this.methodB;
    }
};

Expected behavior:
No errors.

Actual behavior:
testbug.ts(11,14): error TS2339: Property 'methodB' does not exist on type '(Anonymous class)'.

And if you replace this.methodB with this.methodA it typechecks fine when it should not.
This didn't happen in earlier versions, Version 2.0.0 works as expected.

Activity

  1. sandersn commented on Mar 31, 2017

    @sandersn
    Member

    Caching in control flow analysis goes wrong. It requires a loop and a reference to this inside of methodA, so it's a fairly specific set of conditions that triggers it.

  2. sandersn commented on Apr 5, 2017

    @sandersn
    Member

    Fix is up at #15032. The problem was that control flow was treating this like a normal variable reference and walking outside the class expression to try to narrow it. Because of caching, the first type that control flow analysis found for this ({ methodA() { }) was used for this everywhere.

  3. locked and limited conversation to collaborators on Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions