Skip to content

noEmptyInterface

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noEmptyInterface": "error"
}
}
}
}

¥Description

禁止声明空接口。

¥Disallow the declaration of empty interfaces.

TypeScript 中的空接口功能很少:任何非空值都可以分配给 {}。使用空接口通常是程序员错误的标志,例如误解 {} 的概念或忘记填写字段。

¥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.

该规则忽略 extends 一种或多种类型的空接口。

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

¥Examples

¥Invalid

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

¥Valid

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 {}
}

¥Related links