UNPKG

1.62 kBMarkdownView Raw
1# `no-empty-interface`
2
3Disallow the declaration of empty interfaces.
4
5An empty interface is equivalent to its supertype. If the interface does not implement a supertype, then
6the interface is equivalent to an empty object (`{}`). In both cases it can be omitted.
7
8## Rule Details
9
10This rule aims to ensure that only meaningful interfaces are declared in the code.
11
12<!--tabs-->
13
14### ❌ Incorrect
15
16```ts
17// an empty interface
18interface Foo {}
19
20// an interface with only one supertype (Bar === Foo)
21interface Bar extends Foo {}
22
23// an interface with an empty list of supertypes
24interface Baz {}
25```
26
27### ✅ Correct
28
29```ts
30// an interface with any number of members
31interface Foo {
32 name: string;
33}
34
35// same as above
36interface Bar {
37 age: number;
38}
39
40// an interface with more than one supertype
41// in this case the interface can be used as a replacement of a union type.
42interface Baz extends Foo, Bar {}
43```
44
45<!--/tabs-->
46
47### Options
48
49This rule accepts a single object option with the following default configuration:
50
51```json
52{
53 "@typescript-eslint/no-empty-interface": [
54 "error",
55 {
56 "allowSingleExtends": false
57 }
58 ]
59}
60```
61
62- `allowSingleExtends: true` will silence warnings about extending a single interface without adding additional members
63
64## When Not To Use It
65
66If you don't care about having empty/meaningless interfaces, then you will not need this rule.
67
68## Related To
69
70- TSLint: [no-empty-interface](https://palantir.github.io/tslint/rules/no-empty-interface/)
71
72## Attributes
73
74- Configs:
75 - [x] ✅ Recommended
76 - [x] 🔒 Strict
77- [x] 🔧 Fixable
78- [ ] 💭 Requires type information