Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-unnecessary-type-assertion] only checks non-null-assertion #4485

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@c-vetter

Description

@c-vetter
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I haveread the FAQ and my problem is not listed.

Repro

{"root":true,"parser":"@typescript-eslint/parser","parserOptions": {"ecmaVersion":2021,"project":"./tsconfig.json","sourceType":"module"},"plugins": ["@typescript-eslint"],"rules": {"@typescript-eslint/no-unnecessary-type-assertion":"error"}}
// code.tstypeFoo=3constfoox:Foo=3as3constfooy=3asFooconstfooz:Foo=3constfooa=<3>3constfoob=<Foo>3constfooc=3constbar=fooc!functionfoo(x:number):number{returnx!// unnecessary non-null}
{"compilerOptions": {"strict":true },"include": ["./code.ts" ],}

Expected Result

3:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion4:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion7:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion8:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion11:13  error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion14:9   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion✖ 6 problems (6 errors, 0 warnings)

OR (see below)

3:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion4:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion5:7    error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion7:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion8:14   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion11:13  error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion14:9   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion✖ 7 problems (7 errors, 0 warnings)

Actual Result

  11:13  error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion  14:9   error  This assertion is unnecessary since it does not change thetype of the expression  @typescript-eslint/no-unnecessary-type-assertion✖ 2 problems (2 errors, 0 warnings)

Additional Info

ThetypesToIgnore option description implies also checking annotations. Since annotations and assertions are different things, I would expect them to be handled by separate rules. Depending on whether or not they are an intended target for this rule, the first or second expectation should be fulfilled.

Versions

packageversion
@typescript-eslint/eslint-plugin5.10.0
@typescript-eslint/parser5.10.0
TypeScript4.5.5
ESLint8.7.0
node14.17.5,16.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp