コンテンツにスキップ

useConsistentTypeDefinitions

このコンテンツはまだ日本語訳がありません。

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.

type Point = { x: number; y: number; };
code-block.ts:1:1 lint/nursery/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;
}

The following options are available

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

Default: interface

{
"options": {
"style": "type"
}
}
interface Point {
x: number;
y: number;
}
biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentTypeDefinitions": "error"
}
}
}
}