Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
grantwwu opened this issue Feb 22, 2019 · 1 comment
Open

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

grantwwu opened this issue Feb 22, 2019 · 1 comment

Comments

@grantwwu
Copy link

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",
  ]
}
@stephentuso
Copy link
Contributor

Unfortunately this won't be possible until microsoft/TypeScript#27525 is solved. As mentioned there, we can reference custom symbols with typeof, but that doesn't work with well-known symbols such as Symbol.asyncIterator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants