强制使用一致的类型声明样式,仅使用“interface”或者仅使用“type”。
该规则仅支持对.js/.ts文件进行检查。
规则配置
// code-linter.json5
{
"rules": {
"@typescript-eslint/consistent-type-definitions": "error"
}
} 正例
// 基本类型的定义可以使用type
export type T1 = string;
// 默认推荐使用interface 进行对象类型定义
export interface T2 {
x: number;
}
export type Foo = string | T2; 反例
// 默认推荐使用interface 进行对象类型定义
type T = { x: number };