[no-unnecessary-type-assertion] too restrictive with intended temporary narrowing #3187
Closed
3 tasks done
Labels
bug
Something isn't working
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Repro
Release 4.17.0 has changed the rule "no-unnecessary-type-assertion" (PR #3133) in a way that breaks existing code, as it seems it now forbids some legitimate use cases of the
!
operator:Expected Result
Inside the first
if
, the assignment tox
intentionally narrows the result ofpop()
because it's sure that the array is not empty.Actual Result
With v4.17 the narrowing will produce a warning.
Versions
@typescript-eslint/eslint-plugin
4.17.0
@typescript-eslint/parser
4.17.0
TypeScript
4.2.3
ESLint
7.22.0
node
12.16.2
The text was updated successfully, but these errors were encountered: