Skip to content

overloadSignaturesAdjacent

Require that function overload signatures be consecutive.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Function overload signatures represent multiple ways a function can be called with different parameter types or return types. When overload signatures are separated by other code, it becomes harder to see the full API of a function at a glance. Grouping all overload signatures for a function together makes code easier to read and understand.

This rule reports when a function’s overload signatures are not adjacent to each other.

function
function f(x: number): void (+1 overload)
f
(
x: number
x
: number): void;
function
function other(): void
other
(): void {}
function
function f(x: string): void (+1 overload)
f
(
x: string
x
: string): void;
function
function f(x: number): void (+1 overload)
f
(
x: string | number
x
: number | string): void {}
interface
interface I
I
{
I.method(x: number): void (+2 overloads)
method
(
x: number
x
: number): void;
I.other(): void
other
(): void;
I.method(x: string): void (+2 overloads)
method
(
x: string
x
: string): void;
I.method(x: number | string): void (+2 overloads)
method
(
x: string | number
x
: number | string): void;
}

This rule is not configurable.

It can sometimes be useful to place overload signatures alongside other meaningful parts of a type. For example, if each overload corresponds to a different property, you might wish to place each overload next to its property. You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.