src/content/docs/linter/rules/use-consistent-type-definitions.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v2.1.4` - Diagnostic Category: [`lint/style/useConsistentTypeDefinitions`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@typescript-eslint/consistent-type-definitions`](https://typescript-eslint.io/rules/consistent-type-definitions){
"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; };
interface Point {
x: number;
y: number;
}
type AnyObject = {};
The following options are available
styleThis option will determine which style to use for type definitions.
Default: interface
{
"linter": {
"rules": {
"style": {
"useConsistentTypeDefinitions": {
"options": {
"style": "type"
}
}
}
}
}
}
interface Point {
x: number;
y: number;
}