Skip to content

useConsistentTypeDefinitions

biome.json
{
"linter": {
"rules": {
"style": {
"useConsistentTypeDefinitions": "error"
}
}
}
}

Enforce type definitions to consistently use either interface or type.

TypeScript provides two different ways to define an object type: interface and type.

This rule enforces consistent usage of either interface or type for object type definitions. 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.

type Point = { x: number; y: number; };
code-block.ts:1:1 lint/style/useConsistentTypeDefinitions  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use of the type detected.

> 1 │ type Point = { x: number; y: number; };
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

The codebase should use a consistent coding style for the definition of types. This improves the readability and consistency.

Unsafe fix: Use interface.

1 - type·Point·=·{·x:·number;·y:·number;·};
1+ interface·Point·{
2+ ····x:·number;
3+ ····y:·number;
4+ }
2 5

interface Point {
x: number;
y: number;
}
type AnyObject = {};

The following options are available

This option will determine which style to use for type definitions.

Default: interface

biome.json
{
"linter": {
"rules": {
"style": {
"useConsistentTypeDefinitions": {
"options": {
"style": "type"
}
}
}
}
}
}
interface Point {
x: number;
y: number;
}
code-block.ts:1:1 lint/style/useConsistentTypeDefinitions  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use of the interface detected.

> 1 │ interface Point {
^^^^^^^^^^^^^^^^^
> 2 │ x: number;
> 3 │ y: number;
> 4 │ }
^
5 │

The codebase should use a consistent coding style for the definition of types. This improves the readability and consistency.

Unsafe fix: Use type alias.

1 - interface·Point·{
1+ type·Point·=·{
2 2 x: number;
3 3 y: number;
4 - }
4+ };
5 5