Skip to content

Async iterator typecheck bug on class instances that implements AsyncIterable #14442

@Bnaya

Description

@Bnaya

TypeScript Version: 2.3.0-dev.20170303

Code

// A *self-contained* demonstration of the problem follows...

class FooAsyncIterator implements AsyncIterator<string> {
  next(value?: any) {
    return Promise.resolve({
      value: 'foooo',
      done: true
    });

  }
}

class FooAsyncIterable implements AsyncIterable<string> {

  [Symbol.asyncIterator]() {
    return new FooAsyncIterator()
  }
}

const fooBucket2: AsyncIterable<string> = {
  [Symbol.asyncIterator]() {
    return new FooAsyncIterator()
  }
};

const fooAsyncIterable = new FooAsyncIterable();

async function foo() {

// no error here
  for await (const s3obj of fooBucket2) {

  }

  // fooAsyncIterable has error:
  /*
  [ts] The type returned by the 'next()' method of an iterator must have a 'value' property.
  */
  for await (const s3obj of fooAsyncIterable) {

  }
}

Expected behavior:
The build should pass

Actual behavior:
typecheck error:

[ts] The type returned by the 'next()' method of an iterator must have a 'value' property.
const fooAsyncIterable: FooAsyncIterable

you can see the code here:
https://github.com/Bnaya/async-iterator-type-issue/blob/master/src/index.ts

travis build log:
https://travis-ci.org/Bnaya/async-iterator-type-issue/jobs/207521422#L205

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions