diff --git a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md new file mode 100644 index 00000000000..2669d72323c --- /dev/null +++ b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md @@ -0,0 +1,78 @@ +# Consistent with type definition either `interface` or `type` (consistent-type-definitions) + +There are two ways to define a type. + +```js +// type alias +type T1 = { + a: string, + b: number, +}; + +// interface +interface T2 { + a: string; + b: number; +} +``` + +## Rule Details + +Examples of **incorrect** code with `interface` option. + +```ts +type T = { x: number }; +``` + +Examples of **correct** code with `interface` option. + +```ts +type T = string; +type Foo = string | {}; + +interface T { + x: number; +} +``` + +Examples of **incorrect** code with `type` option. + +```ts +interface T { + x: number; +} +``` + +Examples of **correct** code with `interface` option. + +```ts +type T = { x: number }; +``` + +## Options + +This rule has two options: + +```CJSON +{ + // Consistent with type definition by `interface` + "@typescript-eslint/ban-types": ["error", "interface"] +} +``` + +Or for tabbed indentation: + +```CJSON +{ + // Consistent with type definition by `type` + "@typescript-eslint/ban-types": ["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 + +- TSLint: [interface-over-type-literal](https://palantir.github.io/tslint/rules/interface-over-type-literal/) diff --git a/packages/eslint-plugin/docs/rules/prefer-interface.md b/packages/eslint-plugin/docs/rules/prefer-interface.md deleted file mode 100644 index 39c8ca24321..00000000000 --- a/packages/eslint-plugin/docs/rules/prefer-interface.md +++ /dev/null @@ -1,34 +0,0 @@ -# Prefer an interface declaration over a type literal (type T = { ... }) (prefer-interface) - -Interfaces are generally preferred over type literals because interfaces can be implemented, extended and merged. - -## Rule Details - -Examples of **incorrect** code for this rule. - -```ts -type T = { x: number }; -``` - -Examples of **correct** code for this rule. - -```ts -type T = string; -type Foo = string | {}; - -interface T { - x: number; -} -``` - -## Options - -```CJSON -{ - "interface-over-type-literal": "error" -} -``` - -## Compatibility - -- TSLint: [interface-over-type-literal](https://palantir.github.io/tslint/rules/interface-over-type-literal/)