question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

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

See original GitHub issue

TypeScript Version: 3.5.1, 3.7.5, 3.8-Beta

Search Terms: async, await, loop, promise, variable assignment, implicitly has type any, referenced directly or indirectly in its own initializer.

Code

interface Foo {
    id : string,
}

declare function paginate(after: string|undefined): Promise<Foo[]>;

async function main() {
    let after: string | undefined = undefined;
    while (true) {
        const page = await paginate(after);
        for (const foo of page) {
            after = foo.id;
        }
    }   
}

Expected behavior:

Type checks successfully

Actual behavior: image

Playground Link: Playground

Related Issues:

Similar to https://github.com/microsoft/TypeScript/issues/14428 , an already fixed issue.

Similar to https://github.com/microsoft/TypeScript/issues/36666 , but without destructuring; and my initial variable also has explicit type annotations (after : string|undefined)


Workaround

Just use an explicit type annotation,

const page : Foo[] = await paginate(after);

However, it is strange. It shouldnโ€™t need the explicit type annotation because it can only possibly be Foo[].

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:16
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
evenfrostcommented, May 5, 2021

Any update on this? Just faced this very error in the while loop.

1reaction
evenfrostcommented, Feb 7, 2022

Faced this again, found this thread again, realized that I had already commented on this a year ago.

Well, as Iโ€™m back here, any update on this? Removing the async/await stuff from this throws no error, so I believe itโ€™s more like a bug than a design limitation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'items' implicitly has type 'any' because it does not have a type ...
'items' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer....
Read more >
implicitly has return type 'any' because it does not have a return type ...
implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of...
Read more >
Implicitly has return type 'any' because it does not have a ...
Implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly.
Read more >
TypeScript support in Svelte - Learn web development
In this article we took our to-do list application and ported it to TypeScript.
Read more >
Diagnostic messages - Dart programming language
The variable might or might not have been assigned a value, depending on the ... code produces this diagnostic because the class C...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found