Closed
Description
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
Playground Link: Playground
Related Issues:
Similar to #14428 , an already fixed issue.
Similar to #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[]
.