Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 1.27 KB

consistent-type-definitions.md

File metadata and controls

78 lines (56 loc) · 1.27 KB

Consistent with type definition either interface or type (consistent-type-definitions)

There are two ways to define a type.

// type alias
type T1 = {
  a: string,
  b: number,
};

// interface
interface T2 {
  a: string;
  b: number;
}

Rule Details

Examples of incorrect code with interface option.

type T = { x: number };

Examples of correct code with interface option.

type T = string;
type Foo = string | {};

interface T {
  x: number;
}

Examples of incorrect code with type option.

interface T {
  x: number;
}

Examples of correct code with type option.

type T = { x: number };

Options

This rule has two options:

{
    // Consistent with type definition by `interface`
    "@typescript-eslint/consistent-type-definitions": ["error", "interface"]
}

Or for tabbed indentation:

{
    // Consistent with type definition by `type`
    "@typescript-eslint/consistent-type-definitions": ["error", "type"]
}

When Not To Use It

If you specifically want to use an interface or type literal for stylistic reasons, you can disable this rule.

Compatibility