Skip to content

BUG: Wrong type inferred for AsyncIterableIterator #31363

@babakness

Description

@babakness

Search Terms:

AsyncIterableIterator

Code

declare function generatorPipe<A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C
declare function map<A, B>(fn: (p: A) => B): (inputs: Iterable<A>) => AsyncIterableIterator<B>


const foo = generatorPipe(
  map( (i: number ) => i + 1),
  map( (i: number ) => i + 1),
)

Expected behavior:

const foo: (a: Iterable<number>) => AsyncIterableIterator<number>

Actual behavior:

TypeScript seems to infer Iterable for AsyncIterableIterator

Argument of type '(inputs: Iterable) => AsyncIterableIterator' is not assignable to parameter of type '(a: Iterable) => Iterable'.
Property '[Symbol.iterator]' is missing in type 'AsyncIterableIterator' but required in type 'Iterable'.ts(2345)

Note, the following works as expected

declare function generatorPipe<A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C
declare function map<A, B>(fn: (p: A) => B): (inputs: Iterable<A>) => IterableIterator<B>

const foo = generatorPipe(
  map( (i: number ) => i + 1),
  map( (i: number ) => i + 1),
)

const foo =  (a: Iterable<number>) => IterableIterator<number>

Playground Link:

Playground does not support AsyncIterableIterator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions