Skip to content

Circular type false positive with async/await  #51115

Closed
@jeremy-rifkin

Description

@jeremy-rifkin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions