Skip to content

$$asyncIterator doesn't seem to work with TypeScript #49

@grantwwu

Description

@grantwwu

When I define a function with:

public [$$asyncIterator]() {
...
}

instead of

public [Symbol.asyncIterator]() {
...
}

TypeScript's type checking doesn't seem to understand that $$asyncIterator is equivalent to Symbol.asyncIterator. I get the following issue when I try to use a for await... of loop:

src/test/pulsar-client-test.ts:167:37 - error TS2504: Type 'PubSubAsyncIterator<{}>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.

167         for await (const message of ai) {
                                        ~~

my tsconfig.json is:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "noImplicitAny": false,
    "rootDir": "./src",
    "outDir": "./dist",
    "pretty": true,
    "removeComments": true,
    "declaration": true,
    "lib": ["esnext", "dom"]
  },
  "exclude": [
    "node_modules",
    "dist",
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions