Skip to content

Files

Latest commit

 

History

History
57 lines (47 loc) · 1.29 KB

adjacent-overload-signatures.md

File metadata and controls

57 lines (47 loc) · 1.29 KB

Pattern: Scattered function overload signature

Issue: -

Description

Function overload signatures represent multiple ways a function can be called, potentially with different return types. When overload signatures are scattered throughout a type definition rather than placed together, they become harder to discover and maintain, increasing the risk of missed signatures by developers.

Examples

Example of incorrect code:

declare namespace Foo {
  export function foo(s: string): void;
  export function foo(n: number): void;
  export function bar(): void;
  export function foo(sn: string | number): void;
}

type Foo = {
  foo(s: string): void;
  foo(n: number): void;
  bar(): void;
  foo(sn: string | number): void;
};

interface Foo {
  foo(s: string): void;
  foo(n: number): void;
  bar(): void;
  foo(sn: string | number): void;
}

Example of correct code:

declare namespace Foo {
  export function foo(s: string): void;
  export function foo(n: number): void;
  export function foo(sn: string | number): void;
  export function bar(): void;
}

type Foo = {
  foo(s: string): void;
  foo(n: number): void;
  foo(sn: string | number): void;
  bar(): void;
};

interface Foo {
  foo(s: string): void;
  foo(n: number): void;
  foo(sn: string | number): void;
  bar(): void;
}