Skip to content

Circular type false positive with async/await  #51115

Closed

Description

Bug Report

🔎 Search Terms

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

await

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "referenced directly or indirectly"

⏯ Playground Link

Playground link with relevant code

💻 Code

async function get_things(_: number | undefined) {
    return [0];
}

async function foobar() {
    // The error goes away without the `| undefined`
    let before: number | undefined = undefined;
    // The error goes away without the loop
    for(let i = 0; i < 2; i++) {
        // The error goes away without the async/await
        const results = await get_things(before);
        //       ^ 'results' implicitly has type 'any' because it does not have a type annotation
        //          and is referenced directly or indirectly in its own initializer.
        before = results[0];
    }
}

🙁 Actual behavior

This results in an error

'results' implicitly has type 'any' because it does not have a type annotation
and is referenced directly or indirectly in its own initializer.

🙂 Expected behavior

This should not be an error.

Activity

  1. jeremy-rifkin commented on Oct 9, 2022

    @jeremy-rifkin
    Author

    This bug is similar to #48708 but is present as far back as the playground goes (3.3.3). It stands apart largely because of the async/await.

  2. whzx5byb commented on Oct 9, 2022

    @whzx5byb

    Duplicate of #43047

  3. Andarist commented on Oct 9, 2022

    @Andarist
    Contributor

    FYI: I have a fix locally for this one - just need to clean the code up and prepare a PR some time later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions