Skip to content

useAdjacentOverloadSignatures

诊断类别:lint/nursery/useAdjacentOverloadSignatures

¥Diagnostic Category: lint/nursery/useAdjacentOverloadSignatures

自从:v1.9.0

¥Since: v1.9.0

来源:

¥Sources:

禁止使用不相邻的过载签名。

¥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/nursery/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/nursery/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 {};
}

¥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