【问题标题】:How to tell WebStorm or PhpStorm that the code is inside an async function如何告诉 WebStorm 或 PhpStorm 代码在异步函数中
【发布时间】:2020-07-31 22:05:37
【问题描述】:

我正在编写将在异步函数中评估的代码。此代码未包装在此文件中的函数中,因此所有“等待”都带有下划线作为检查错误。

有没有办法告诉 IDE 它是异步上下文并且所有“等待”都可以?

UPD 1:

代码评估:

const m = {};
const AF = Object.getPrototypeOf(async function(){}).constructor;
async function evl(n){
    if(typeof m[n] === t.U) await (new AF('imp', 'exp', await get('http://localhost/mdl/' + n + '.js')))(imp, o=>{m[n]=o});
    return m[n];
}

代码来源:

const message = await imp('message'); // await gives inspection error.
exp((name)=>console.log(message + ', ' + name + '!'));

【问题讨论】:

  • 您可以suppress certain inspections 获取该文件,但我更想知道您的代码是什么样的以及您是如何评估它的?也许有一种方法可以在不违反规则的情况下编写您想要的内容?
  • @chazsolo 添加了一些代码。

标签: javascript asynchronous phpstorm webstorm jsdoc


【解决方案1】:

自 2020.2 起,JavaScript 和 TypeScript |异步代码和承诺 |顶级'await'表达式默认关闭;如果它已为您启用,请尝试在 设置 | 中禁用它。编辑 |检查

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2019-01-16
    相关资源
    最近更新 更多