no-empty-object-type
禁止意外使用 "空对象" 类型.
✅
在 ESLint 配置 中扩展"plugin:@typescript-eslint/recommended" 可启用此规则。
💡
此规则报告的一些问题可以通过编辑器 建议 手动修复。
TypeScript 中的 {} 或 "空对象" 类型是让不熟悉 TypeScript 结构类型的开发者感到困惑的常见原因。{} 表示任何非空值,包括像 0 和 "" 这样的字面量:
¥The {}, or "empty object" type in TypeScript is a common source of confusion for developers unfamiliar with TypeScript's structural typing.
{} represents any non-nullish value, including literals like 0 and "":
let anyNonNullishValue: {} = 'Intentionally allowed by TypeScript.';
通常,开发者编写 {} 的意思是:
¥Often, developers writing {} actually mean either:
-
object:表示任何对象值¥
object: representing any object value -
unknown