Skip to content

Async methods that return this are considered circular references #47291

@matthewvalentine

Description

@matthewvalentine

Bug Report

🔎 Search Terms

circular method this async implicitly has type any because it does not have a type annotation and is referenced directly or indirectly in its own initializer

🕗 Version & Regression Information

  • This changed between versions 4.4.4 and 4.5.4 and is not fixed in Nightly

⏯ Playground Link

Playground link with relevant code

💻 Code

class X {
    // This is ok in 4.4.4, but has 'any' type due to a circular reference in 4.5.4
    bad = async (): Promise<this> => this;

    // These all work in both versions (just to narrow down the breadth of the problem)
    ok1 = (): this => this;
    ok2 = (): this[] => [this];
    ok3 = (): Promise<this> => Promise.resolve(this);
    ok4 = (): Promise<this> => (async () => this)();
}

🙁 Actual behavior

The async bad method triggers the error 'bad' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. Although the playground does display () => Promise<this> as the type on hover.

🙂 Expected behavior

There should be no error in the example. There was not in 4.4.4 and the method is not fundamentally different from some of the ok examples (especially ok3 and ok4.)

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions