useUnifiedTypeSignatures
Ce contenu n’est pas encore disponible dans votre langue.
Summary
Section titled “Summary”- Rule available since: 
v2.1.0 - Diagnostic Category: 
lint/style/useUnifiedTypeSignatures - This rule has an unsafe fix.
 - The default severity of this rule is information.
 - Sources:
 
How to configure
Section titled “How to configure”{  "linter": {    "rules": {      "style": {        "useUnifiedTypeSignatures": "error"      }    }  }}Description
Section titled “Description”Disallow overload signatures that can be unified into a single signature.
Overload signatures that can be merged into a single signature are redundant and should be avoided. This rule helps simplify function signatures by combining overloads by making parameters optional and/or using type unions.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”function f(a: number): void;function f(a: string): void;code-block.ts:1:1 lint/style/useUnifiedTypeSignatures  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ℹ Overload signatures are hard to read and maintain.
  
  > 1 │ function f(a: number): void;
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ function f(a: string): void;
    3 │ 
  
  ℹ Unsafe fix: Combine overloads using a type union.
  
    1   │ - function·f(a:·number):·void;
    2   │ - function·f(a:·string):·void;
      1 │ + 
      2 │ + function·f(a:·string·|·number):·void;
    3 3 │   
  
interface I {    a(): void;    a(x: number): void;}code-block.ts:2:5 lint/style/useUnifiedTypeSignatures  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ℹ Overload signatures are hard to read and maintain.
  
    1 │ interface I {
  > 2 │     a(): void;
      │     ^^^^^^^^^^
    3 │     a(x: number): void;
    4 │ }
  
  ℹ Unsafe fix: Combine overloads by making parameters optional.
  
    1 1 │   interface I {
    2   │ - ····a():·void;
    3   │ - ····a(x:·number):·void;
      2 │ + ····a(x?:·number):·void;
    4 3 │   }
    5 4 │   
  
function f(a: number | string): void {}interface I {    a(x?: number): void;}Different return types cannot be merged:
interface I {    f(): void;    f(x: number): number;}Different type parameters cannot be merged:
function f<T extends number>(x: T): void;function f<T extends string>(x: T): void;function f(x: unknown): void {}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.