noEmptyInterface (since v11.0.0)
Disallow the declaration of empty interfaces.
An empty interface in TypeScript does very little: any non-nullable value is assignable to
{}
. Using an empty interface is often a sign of programmer error, such as misunderstanding the concept of{}
or forgetting to fill in fields.
Source: https://typescript-eslint.io/rules/no-empty-interface
Examples
Invalid
interface A {}
nursery/noEmptyInterface.js:1:1 lint/nursery/noEmptyInterface FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ An empty interface is equivalent to '{}'.
> 1 │ interface A {}
│ ^^^^^^^^^^^^^^
2 │
ℹ Safe fix: Convert empty interface to type alias.
1 │ - interface·A·{}
1 │ + type·A·=·{}
2 2 │
// A === B
interface A extends B {}
nursery/noEmptyInterface.js:2:1 lint/nursery/noEmptyInterface FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ An interface declaring no members is equivalent to its supertype.
1 │ // A === B
> 2 │ interface A extends B {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^
3 │
ℹ Safe fix: Convert empty interface to type alias.
1 1 │ // A === B
2 │ - interface·A·extends·B·{}
2 │ + type·A·=·B
3 3 │
Valid
interface A {
prop: string;
}
// The interface can be used as an union type.
interface A extends B, C {}