typescript/unified-signatures Style
作用
不允许可以合并为一个的重载签名。
为什么这不好?
仅在单个类型不同,或仅在可选/剩余参数不同的重复重载签名,比一个统一的签名更难维护和阅读。
示例
以下是此规则的错误代码示例:
ts
function f(a: number): void;
function f(a: string): void;以下是此规则的正确代码示例:
ts
function f(a: number | string): void;配置
此规则接受一个包含以下属性的配置对象:
ignoreDifferentlyNamedParameters
type: boolean
default: false
在比较签名时,是否忽略参数名差异。如果为 false,那么即使参数类型相同,只要签名在相同位置上的参数名称不同,也不会被视为可统一。
ignoreOverloadsWithDifferentJSDoc
type: boolean
default: false
在比较签名时,是否忽略 JSDoc 差异。如果为 false,那么即使签名本身完全相同,只要这些签名最接近的前导块注释不同,也不会被视为可统一。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"typescript/unified-signatures": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"typescript/unified-signatures": "error",
},
});bash
oxlint --deny typescript/unified-signatures版本
此规则于 v1.48.0 中添加。
