typescript/consistent-type-definitions Style
What it does
Enforce type definitions to consistently use either interface or type.
Why is this bad?
TypeScript provides two common ways to define an object type: interface and type. The two are generally very similar, and can often be used interchangeably. Using the same type declaration style consistently helps with code readability.
Examples
By default this rule enforces the use of interfaces for object types.
Examples of incorrect code for this rule:
type T = { x: number };
Examples of correct code for this rule:
type T = string;
type Foo = string | {};
interface T {
x: number;
}
Options
This rule has a single string option:
{ type: string, default: "interface" }
interface
This is the default option.
type
Enforces the use of types for object type definitions.
Examples of incorrect code for this option:
interface T {
x: number;
}
Examples of correct code for this option:
type T = { x: number };
How to use
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny typescript/consistent-type-definitions
{
"rules": {
"typescript/consistent-type-definitions": "error"
}
}