Error message on use of async iterators in nodeJS 10 streams misleading #26677
Labels
Bug
A bug in TypeScript
Domain: lib.d.ts
The issue relates to the different libraries shipped with TypeScript
Milestone
TypeScript Version: [email protected]
Search Terms: async iterator ES2018
Code
Expected behavior:
No error message. Fallback code generation or polyfill based
Symbol.asyncIterator
.Actual behavior:
Message: message index.ts:12:25 - error TS2519: An async iterator must have a 'next()' method.
This error message is wrong, because the code generated (
__asyncValues
) depends on[Symbol.asyncIterator]
rather thannext()
on the stream.Playground Link: Playground does not behave the same, it currently generates different code that actually does depend on a
next()
method, so this link is not particularly useful.Related Issues: #20463, the fix here might make the message go away, just as using --target ESNEXT does, but I think that misses the point. Shouldn't the --target option control the choice of generated language, and not what input syntax is permitted?
This currently happens for If --target ES2015, ES2016, ES2017, or ES2018, but not ESNEXT. If --target ES5, a different error is generated, requiring a
Promise
constructor.I'm hoping we should be able to polyfill async iterators into any implementation support promises and symbols.,
Note: the of the @types/[email protected] version of index.d.ts I'm using does declare that stream has a
[Symbol.asyncIterator]
method. If it lacked that, then the message displayed might make sense, but as the generated code never even uses next() method, the message is still confusing..The text was updated successfully, but these errors were encountered: