Skip to main content

no-empty-interface

Disallow the declaration of empty interfaces.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

💡

Some problems reported by this rule are manually fixable by editor suggestions.

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.

This rule aims to ensure that only meaningful interfaces are declared in the code.

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-empty-interface": "error"
}
};

Examples

// an empty interface
interface Foo {}

// an interface with only one supertype (Bar === Foo)
interface Bar extends Foo {}

// an interface with an empty list of supertypes
interface Baz {}

Options

This rule accepts an options object with the following properties:

interface Options {
allowSingleExtends?: boolean;
}

const defaultOptions: Options = [{ allowSingleExtends: false }];

This rule accepts a single object option with the following default configuration:

{
"@typescript-eslint/no-empty-interface": [
"error",
{
"allowSingleExtends": false
}
]
}
  • allowSingleExtends: true will silence warnings about extending a single interface without adding additional members

When Not To Use It

If you don't care about having empty/meaningless interfaces, then you will not need this rule.

Resources