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 issueTypeScript 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:
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:
- Created 4 years ago
- Reactions:16
- Comments:15 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any update on this? Just faced this very error in the
while
loop.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.