Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-parts-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#8759](https://github.com/biomejs/biome/issues/8759): The [`useConsistentTypeDefinitions`](https://biomejs.dev/linter/rules/use-consistent-type-definitions/) rule no longer converts empty object type declarations into interfaces, as it will conflict with the [`noEmptyInterface`](https://biomejs.dev/linter/rules/no-empty-interface/) rule and can cause an infinite loop when both rules are enabled.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ declare_lint_rule! {
/// Consistent type definition styles, aside from improving code readability, help minimize cognitive load when developers
/// switch between different codebases or within a large codebase.
///
/// Empty object type declarations will be left as-is and will not be converted to interfaces,
/// as it will conflict with the `noEmptyInterface` rule.
///
/// ## Example
///
/// ### Invalid
Expand All @@ -40,6 +43,10 @@ declare_lint_rule! {
/// }
/// ```
///
/// ```ts
/// type AnyObject = {};
/// ```
///
/// ## Options
///
/// The following options are available
Expand Down Expand Up @@ -180,8 +187,16 @@ fn can_convert_interface_to_type(interface_decl: &TsInterfaceDeclaration) -> boo
fn can_convert_type_to_interface(type_alias: &TsTypeAliasDeclaration) -> bool {
// Check if the type alias has type parameters
// Type aliases with complex types cannot be converted to interfaces
let Ok(AnyTsType::TsObjectType(ty)) = type_alias.ty() else {
return false;
};

matches!(type_alias.ty(), Ok(AnyTsType::TsObjectType(_)))
// Converting empty types into interfaces will conflict with the `noEmptyInterface` rule
if ty.members().is_empty() {
return false;
}

true
}

fn convert_interface_to_type_alias(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ type Nullable<T> = T | null;
// Interfaces can extend
interface ExtendedInterface extends Foo {
extra: boolean;
}
}

// Empty types will be left as-is
type AnyObject = {};
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ type Nullable<T> = T | null;
interface ExtendedInterface extends Foo {
extra: boolean;
}

// Empty types will be left as-is
type AnyObject = {};

```