Skip to content
← Back to rules

jsdoc/require-throws-type 吹毛求疵

作用

要求 @throws 标签带有类型。

为什么这不好?

@throws 标签应记录可能抛出的错误类型。

示例

此规则的 错误 代码示例:

js
/** @throws */
function quux() {
  throw new Error("error");
}

此规则的 正确 代码示例:

js
/** @throws {Error} */
function quux() {
  throw new Error("error");
}

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsdoc"],
  "rules": {
    "jsdoc/require-throws-type": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsdoc"],
  rules: {
    "jsdoc/require-throws-type": "error",
  },
});
bash
oxlint --deny jsdoc/require-throws-type --jsdoc-plugin

版本

此规则在 v1.65.0 中添加。

参考资料