{"record":{"id":"1c003dd8f16268e4","repo":"oxc-project/oxc","slug":"do-not-use-an-empty-interface-declaration","errorCode":null,"errorMessage":"Do not use an empty interface declaration.","messagePattern":"Do not use an empty interface declaration\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs","lineNumber":27,"sourceCode":"use oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::RuleFixer,\n    rule::{DefaultRuleConfig, Rule},\n    utils::deserialize_regex_option,\n};\n\nfn no_empty_object_type_diagnostic<S: Into<Cow<'static, str>>>(\n    span: Span,\n    message: S,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message)\n        .with_help(\"To avoid confusion around the {} type allowing any non-nullish value, this rule bans usage of the {} type.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoEmptyObjectType(Box<NoEmptyObjectTypeConfig>);\n\n#[expect(clippy::struct_field_names)]\n#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoEmptyObjectTypeConfig {\n    /// Whether to allow empty interfaces.\n    allow_interfaces: AllowInterfaces,\n    /// Whether to allow empty object type literals.\n    allow_object_types: AllowObjectTypes,\n    /// A stringified regular expression to allow interfaces and object type aliases with the configured name.\n    ///\n    /// This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`.","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs#L9-L45","documentation":"Diagnostic from oxlint's port of typescript-eslint's no-empty-object-type rule. An interface with no members (interface Foo {}) behaves like the {} type and accepts any non-nullish value, so the rule bans it to prevent silent loss of type safety; the help text at crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs:19 states exactly this. It fires when the rule visits an empty TSInterfaceDeclaration that the config (allowInterfaces, allowWithName) does not exempt.","triggerScenarios":"Writing `interface Foo {}` with an empty body; writing `interface Foo extends Bar {}` that adds no new members; an ambient .d.ts stub whose members were all removed; an interface whose name does not match the allowWithName regex.","commonSituations":"Placeholder types left over from prototyping, Flow-to-TypeScript migrations where empty interfaces were idiomatic, declaration merging that leaves one empty declaration, enabling the typescript restriction preset in oxlint which turns this rule on.","solutions":["Add at least one real member to the interface","Replace it with a type alias that models the intended shape","If you truly mean 'exactly the empty object', use `type Foo = Record<string, never>`","Configure allowInterfaces or allowWithName in oxlintrc when the empty interface is intentional","Suppress once with `// oxlint-disable-next-line typescript/no-empty-object-type`"],"exampleFix":"// before\ninterface User {}\n\n// after\ninterface User {\n  id: string;\n}","handlingStrategy":"validation","validationCode":"# .github/workflows/lint.yml\n- run: npx oxlint --deny-warnings .\n\n# or configure the exemption up front in oxlintrc.json\n{\n  \"rules\": {\n    \"typescript/no-empty-object-type\": [\"error\", { \"allowWithName\": \"^(?:I|Props|Params)$\" }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run oxlint in CI and as a pre-commit hook so empty interfaces never land on main","Adopt Record<string, never> as the codebase's only spelling of 'intentionally empty object'","During Flow-to-TS migrations, grep for `interface \\w+ {}` before flipping the lint tier"],"tags":["typescript","lint","interface","type-safety"],"backgroundTag":"empty-interface","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}