typescript/no-unnecessary-type-conversion Suspicious
它的作用
禁止不必要的类型转换表达式。
为什么这不好?
不会改变值的类型或运行时行为的类型转换会增加噪音,并可能掩盖意图。
示例
此规则的错误代码示例:
ts
const value = String("asdf");此规则的正确代码示例:
ts
const value = "asdf";如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"options": {
"typeAware": true
},
"rules": {
"typescript/no-unnecessary-type-conversion": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
options: { typeAware: true },
rules: {
"typescript/no-unnecessary-type-conversion": "error",
},
});bash
oxlint --type-aware --deny typescript/no-unnecessary-type-conversion版本
此规则已在 v1.49.0 中添加。
