目录

@typescript-eslint/no-unnecessary-type-assertion

Disallow type assertions that do not change the type of an expression.

Such type assertions are considered unnecessary.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-unnecessary-type-assertion": "error"
  }
}

Options

For details, see @typescript-eslint/no-unnecessary-type-assertion.

Example of Correct Code

const num = 3;
export const foo2 = num as number;
export const foo3 = 'foo' as string;

Example of Incorrect Code

const num = 3;
export const foo = num;
export const bar = foo!;

Rule Set

plugin:@typescript-eslint/all

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