UNPKG

1.19 kBMarkdownView Raw
1# Disallow the declaration of empty interfaces (no-empty-interface)
2
3An empty interface is equivalent to its supertype. If the interface does not implement a supertype, then
4the interface is equivalent to an empty object (`{}`). In both cases it can be omitted.
5
6## Rule Details
7
8This rule aims to ensure that only meaningful interfaces are declared in the code.
9
10The following patterns are considered warnings:
11```ts
12// an empty interface
13interface Foo { }
14
15// an interface with only one supertype (Bar === Foo)
16interface Bar extends Foo { }
17
18// an interface with an empty list of supertypes
19interface Baz extends { }
20```
21
22The following patterns are not warnings:
23```ts
24// an interface with any number of members
25interface Foo {
26 name: string;
27}
28
29// same as above
30interface 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.
36interface Baz extends Foo, Bar { }
37```
38
39## When Not To Use It
40
41If 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