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;
}Configuration
This rule accepts a configuration object with the following properties:
config
type: "interface" | "type"
default: "interface"
Configuration option to enforce either 'interface' or 'type' for object type definitions.
Setting to 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"
}
}