Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

no-useless-cast false positive #834

Open
eranshabi opened this issue Mar 6, 2019 · 1 comment
Open

no-useless-cast false positive #834

eranshabi opened this issue Mar 6, 2019 · 1 comment

Comments

@eranshabi
Copy link

eranshabi commented Mar 6, 2019

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

@saberduck
Copy link
Contributor

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants