强制使用一致的类型断言。
规则配置
// code-linter.json5
{
"rules": {
"@typescript-eslint/consistent-type-assertions": "error"
}
} 正例
interface MyType {
name: string;
}
export const x: MyType = {
name: 'hello'
};
// 默认推荐使用 value as Type:始终优先选择const x = value as Type; 而不是const x = <Type>value;
export const y = x as object; 反例
interface MyType {
name: string;
}
export const x: MyType = {
name: 'hello'
};
// 默认推荐使用 value as Type:始终优先选择const x = value as Type; 而不是const x = <Type>value;
export const y = <object>x;