Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(eslint-plugin): write a doc for consistent-type-definitions
- Loading branch information
1 parent
533c4a3
commit 177973f
Showing
2 changed files
with
78 additions
and
34 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/eslint-plugin/docs/rules/consistent-type-definitions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/) |
This file was deleted.
Oops, something went wrong.