Skip to content

Circular type false positive with async/await #51115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeremy-rifkin opened this issue Oct 9, 2022 · 3 comments · Fixed by #51126
Closed

Circular type false positive with async/await #51115

jeremy-rifkin opened this issue Oct 9, 2022 · 3 comments · Fixed by #51126
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@jeremy-rifkin
Copy link

jeremy-rifkin commented Oct 9, 2022

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.

@jeremy-rifkin
Copy link
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.

@whzx5byb
Copy link

whzx5byb commented Oct 9, 2022

Duplicate of #43047

@Andarist
Copy link
Contributor

Andarist commented Oct 9, 2022

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
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
4 participants