typescript/no-useless-default-assignment Correctness
它的作用
禁止永远不会被使用的默认赋值。
为什么这不好?
当值永远不可能是 undefined 时,默认赋值就是多余的。 这会增加运行时逻辑和噪音,而不会改变行为。
示例
以下是此规则的错误代码示例:
ts
[1, 2, 3].map((a = 0) => a + 1);以下是此规则的正确代码示例:
ts
[1, 2, 3].map((a) => a + 1);如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"options": {
"typeAware": true
},
"rules": {
"typescript/no-useless-default-assignment": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
options: { typeAware: true },
rules: {
"typescript/no-useless-default-assignment": "error",
},
});bash
oxlint --type-aware --deny typescript/no-useless-default-assignment版本
此规则已在 v1.49.0 中添加。
