跳到主要内容

@typescript-eslint/consistent-type-assertions

强制使用一致的类型断言。

规则配置​

// code-linter.json5
{
"rules": {
"@typescript-eslint/consistent-type-assertions": "error"
}
}

选项​

详情请参考@typescript-eslint/consistent-type-assertions选项。

正例​

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;

规则集​

plugin:@typescript-eslint/all

Code Linter代码检查规则的配置指导请参考Code Linter代码检查。