SonarTS
SonarTS copied to clipboard
no-useless-cast false positive
I want to report a bug.
SonarTS version: 1.9.0
Node.js version: 10
TypeScript version: 3.3.3333
TSLint version: 5.13.1
Rule key: no-useless-cast Reproducer
// minimal reproducer if relevant
page.waitFor(() => (document.querySelector('some-query') as HTMLImageElement).complete); // False-positive here
Logs
ERROR: 8:17 no-useless-cast Remove this unnecessary cast.
Expected behavior
cast is not useless because document.querySelector returns Element
which has no complete
attribute, so it needs to be cast to HTMLImageElement
If I delete the cast I will get Type error: Property 'complete' does not exist on type 'Element'. TS2339
hello @eranshabi ,
I am not able to reproduce this issue with TypeScript 3.4.5 . This rule just uses information from TypeScript compiler, and consequently, it will depend on the type definitions for DOM. Can you try to upgrade your TypeScript version and see if the issue persists?