You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple warning when someone uses forEach(async. It's such an easy stumbling block for those entering the async/await world. A user never wants to write that code intentionally
Use Cases
I didn't know that forEach(async ... simply doesn't work (even though linting passes, and similar things like .map(async and relatives are fine.
Examples
Wherever the parser encounters forEach(async it marks it as an error.
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
I think this is probably the domain of a new lint rule - generally speaking, any non-undefined returning function used with Array.prototype.forEach is probably an error, since the return type is unused, but there's technically nothing wrong with it - forEach'ing over a function with a real-valued return type (eg, Promise) for sideeffects is potentially valid.
Activity
weswigham commentedon Nov 19, 2018
I think this is probably the domain of a new lint rule - generally speaking, any non-
undefinedreturning function used withArray.prototype.forEachis probably an error, since the return type is unused, but there's technically nothing wrong with it -forEach'ing over a function with a real-valued return type (eg,Promise) for sideeffects is potentially valid.ajafff commentedon Nov 23, 2018
It turns out it's not too difficult to implement. So there you have it: https://github.com/fimbullinter/wotan/blob/master/packages/mimir/docs/async-function-assignability.md
This rule does exactly what is asked for in the opening post. It covers a lot more cases and should detect almost all assignments of async functions to
void-returning functions.Have a look at the documentation of the linter for a quick start guide: https://github.com/fimbullinter/wotan/blob/master/packages/wotan/README.md
chaffeqa commentedon Nov 23, 2018
that is Klaus Meinhardt (@ajafff) would love to get that into our codebase... so you know, i can stop making terrible bugs for myself 😆