Skip to content

Wrong type inferred in for-await-of of Iterable<Promise<any>> #24570

Closed
@ajafff

Description

@ajafff

TypeScript Version: 3.0.0-dev.20180601

Search Terms: for iterable

Code

// @target: esnext
async function main(p: Iterable<Promise<number>>) {
    for await (const item of p) {
        item; // should be of type 'number'
    }
}

Expected behavior:

item should be of type number to match the runtime value

Actual behavior:

item is incorrectly inferred as Promise<number>

Playground Link: https://agentcooper.github.io/typescript-play/?target=5#code/IYZwngdgxgBAZgV2gFwJYHsIwLbFRACgAcAuGASWQFMAnYAIwBsqAeABRvW1RFYgWz1aAPmEBKGAG8AUDDnx0NGMADueZDAJRMIDamrYY6ODCISZ8yzH1VsAblnyAvtKdA

Related Issues:
#21115 This issue contains a detailed explanation and is not (completely) fixed by the recent changes by @rbuckton

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions