目录

@typescript-eslint/consistent-type-assertions

Enforce consistent usage of type assertions.

Rule Configuration

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

Options

For details, see @typescript-eslint/consistent-type-assertions.

Example of Correct Code

interface MyType {
  name: string;
}
export const x: MyType = {
  name: 'hello'
};
// You are advised to use value as Type by default. Always prefer const x = value as Type over const x = <Type>value.
export const y = x as object;

Example of Incorrect Code

interface MyType {
  name: string;
}
export const x: MyType = {
  name: 'hello'
};
// You are advised to use value as Type by default. Always prefer const x = value as Type over const x = <Type>value.
export const y = <object>x;

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.