1 | # Disallow the declaration of empty interfaces (no-empty-interface)
|
2 |
|
3 | An empty interface is equivalent to its supertype. If the interface does not implement a supertype, then
|
4 | the interface is equivalent to an empty object (`{}`). In both cases it can be omitted.
|
5 |
|
6 | ## Rule Details
|
7 |
|
8 | This rule aims to ensure that only meaningful interfaces are declared in the code.
|
9 |
|
10 | The following patterns are considered warnings:
|
11 | ```ts
|
12 | // an empty interface
|
13 | interface Foo { }
|
14 |
|
15 | // an interface with only one supertype (Bar === Foo)
|
16 | interface Bar extends Foo { }
|
17 |
|
18 | // an interface with an empty list of supertypes
|
19 | interface Baz extends { }
|
20 | ```
|
21 |
|
22 | The following patterns are not warnings:
|
23 | ```ts
|
24 | // an interface with any number of members
|
25 | interface Foo {
|
26 | name: string;
|
27 | }
|
28 |
|
29 | // same as above
|
30 | interface Bar {
|
31 | age: number;
|
32 | }
|
33 |
|
34 | // an interface with more than one supertype
|
35 | // in this case the interface can be used as a replacement of a union type.
|
36 | interface Baz extends Foo, Bar { }
|
37 | ```
|
38 |
|
39 | ## When Not To Use It
|
40 |
|
41 | If you don't care about having empty/meaningless interfaces, then you will not need this rule.
|
42 |
|
43 | ## Compatibility
|
44 |
|
45 | * TSLint: [no-empty-interface](https://palantir.github.io/tslint/rules/no-empty-interface/) |
\ | No newline at end of file |