useAdjacentOverloadSignatures
¥Summary
-
规则生效日期:
v1.9.0¥Rule available since:
v1.9.0 -
诊断类别:
lint/suspicious/useAdjacentOverloadSignatures¥Diagnostic Category:
lint/suspicious/useAdjacentOverloadSignatures -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "useAdjacentOverloadSignatures": "error" } } }}¥Description
禁止使用不相邻的过载签名。
¥Disallow the use of overload signatures that are not next to each other.
重载签名必须相邻。如果多次定义一个键,则只有最后一个定义生效。以前的定义被忽略。此规则对于防止不相邻的意外过载很有用。建议保持重载签名相邻,以使代码更易于阅读和维护。
¥Overload signatures must be adjacent. If a key is defined multiple times, only the last definition takes effect. Previous definitions are ignored. This rule is useful for preventing accidental overloads that are not adjacent. It is recommended to keep the overload signatures adjacent to make the code easier to read and maintain.
¥Examples
¥Invalid
type Foo = { foo_type(s: string): void; foo_type(n: number): void; bar_type(): void; foo_type(sn: string | number): void;};code-block.ts:5:3 lint/suspicious/useAdjacentOverloadSignatures ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ All foo_type signatures must be adjacent.
3 │ foo_type(n: number): void;
4 │ bar_type(): void;
> 5 │ foo_type(sn: string | number): void;
│ ^^^^^^^^
6 │ };
7 │
interface Foo { foo_interface(s: string): void; foo_interface(n: number): void; bar_interface(): void; foo_interface(sn: string | number): void;}code-block.ts:5:3 lint/suspicious/useAdjacentOverloadSignatures ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ All foo_interface signatures must be adjacent.
3 │ foo_interface(n: number): void;
4 │ bar_interface(): void;
> 5 │ foo_interface(sn: string | number): void;
│ ^^^^^^^^^^^^^
6 │ }
7 │
class A { fooA(s: string): void; fooA(n: number): void; barA(): void {}; fooA(sn: string | number): void {};}code-block.ts:5:3 lint/suspicious/useAdjacentOverloadSignatures ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ All fooA signatures must be adjacent.
3 │ fooA(n: number): void;
4 │ barA(): void {};
> 5 │ fooA(sn: string | number): void {};
│ ^^^^
6 │ }
7 │
¥Valid
declare namespace Foo { export function foo_declare(s: string): void; export function foo_declare(n: number): void; export function foo_declare(sn: string | number): void; export function bar_declare(): void;}type Foo = { foo_type(s: string): void; foo_type(n: number): void; foo_type(sn: string | number): void; bar_type(): void;};interface Foo { foo_interface(s: string): void; foo_interface(n: number): void; foo_interface(sn: string | number): void; bar_interface(): void;}class A { fooA(s: string): void; fooA(n: number): void; fooA(sn: string | number): void {} barA(): void {}}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号