admin管理员组文章数量:1430022
When I place this code for a promise that the result is not needed to proceed:
await resultNotNeeded(bla, foo);
I'm getting this eslint error:
[eslint] Expected an assignment or function call and instead saw an expression. (no-unused-expressions)
If the code is like this:
const dummy = await resultNotNeeded(bla, foo);
Then the eslint error is:
[eslint] 'dummy' is defined but never used (no-unused-vars)
Anyone knows how this should be fixed (I know I could do // eslint-disable-line no-unused-expressions
but I'm looking if there is a better syntax for this statement.
When I place this code for a promise that the result is not needed to proceed:
await resultNotNeeded(bla, foo);
I'm getting this eslint error:
[eslint] Expected an assignment or function call and instead saw an expression. (no-unused-expressions)
If the code is like this:
const dummy = await resultNotNeeded(bla, foo);
Then the eslint error is:
[eslint] 'dummy' is defined but never used (no-unused-vars)
Anyone knows how this should be fixed (I know I could do // eslint-disable-line no-unused-expressions
but I'm looking if there is a better syntax for this statement.
- What if the async code fails? – thefourtheye Commented Oct 2, 2016 at 12:06
- Well if you don't need the result, then it is an unused expression. Just disable the rule. – Bergi Commented Oct 2, 2016 at 12:57
-
1
Admittedly, it's a bug in the rule. If they want to allow function calls for side effects, they should also allow
await
expressions. Please report it at eslints issue tracker. – Bergi Commented Oct 2, 2016 at 14:55 -
@thefourtheye, for that case, which I think is not the problem here, await is surrounded in a
try {} catch {}
block which I haven't written here to simplify and focus the question to the problem. @bergi, thanks, it was a problem that eslint was not updated – David Commented Oct 2, 2016 at 20:14 -
1
"Does it mean that I can't use it in node with babel?" No, Babel allows you to use (future) features that are not natively supported yet. That's exactly what Babel enables you to do. "What are the implications?" Just that is not officially part of the language yet. "Will be a polyfill always needed?" Once the feature is officially part of the language, engines will natively support it (sonner or later). ES7 (ES2016) was released around June this year.
async/await
is currently a proposal scheduled for release next year: github./tc39/proposals/blob/master/finished-proposals.md – Felix Kling Commented Oct 3, 2016 at 17:54
1 Answer
Reset to default 5This problem is fixed in [email protected]
.
The problem is that eslint was not updated in my system, I had [email protected]
. Also npm was not up to date, so npm i eslint@latest -g
was not updating eslint.
I had to install [email protected]
(firstly I updated to [email protected]
but it was not working, so I had to download source code from npm github and sudo make install
) and then I could update [email protected]
.
Hope it helps!
版权声明:本文标题:javascript - eslint await Expected an assignment or function call and instead saw an expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745418356a2657790.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论