SonarTS icon indicating copy to clipboard operation
SonarTS copied to clipboard

no-useless-cast false positive

Open eranshabi opened this issue 5 years ago • 1 comments

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

eranshabi avatar Mar 06 '19 13:03 eranshabi

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?

saberduck avatar May 24 '19 08:05 saberduck