Pular para o conteúdo

noEmptyInterface

Este conteúdo não está disponível em sua língua ainda.

Diagnostic Category: lint/suspicious/noEmptyInterface

Since: v1.0.0

Sources:

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.

The rule ignores empty interfaces that extends one or multiple types.

interface A {}
code-block.ts:1:1 lint/suspicious/noEmptyInterface  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

An empty interface is equivalent to {}.

> 1 │ interface A {}
^^^^^^^^^^^^^^
2 │

Safe fix: Use a type alias instead.

1 - interface·A·{}
1+ type·A·=·{}
2 2

interface A {
prop: string;
}
// Allow empty interfaces that extend a type.
interface B extends A {}
// Allow empty interfaces in ambient modules
declare module "mod" {
interface C {}
}