Skip to content
← Back to rules

promise/no-new-statics 正确性

An auto-fix is available for this rule.

它做了什么

禁止对静态 Promise 方法使用 new

为什么这是个问题?

使用 new 调用静态 Promise 方法是无效的,将在运行时导致 TypeError

示例

此规则的错误代码示例:

javascript
const x = new Promise.resolve(value);

此规则的正确代码示例:

javascript
const x = Promise.resolve(value);

如何使用

通过配置文件或 CLI 启用此规则,可以使用:

json
{
  "plugins": ["promise"],
  "rules": {
    "promise/no-new-statics": "error"
  }
}
bash
oxlint --deny promise/no-new-statics --promise-plugin

参考资料