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

"no-unnecessary-type-assertion" flags necessary assertion Element as HTMLElement #3569

Closed
aaronbeall opened this issue Dec 11, 2017 · 2 comments

Comments

@aaronbeall
Copy link

aaronbeall commented Dec 11, 2017

Bug Report

  • TSLint version: ^5.8.0
  • TypeScript version: ^2.6.2
  • Running TSLint via: Package script: tslint --format stylish --project tsconfig.json

TypeScript code being linted

(ReactDOM.findDOMNode(this.toggle) as HTMLElement).focus()

with tslint.json configuration:

{
"no-unnecessary-type-assertion": true
}

Actual behavior

no-unnecessary-type-assertion This assertion is unnecessary since it does not change the type of the expression.

Expected behavior

No error. findDOMNode() returns Element which has no focus() method, subclass HTMLElement does so assertion is necessary.

The findDOMNode() definition from @types/react-dom looks like this:

declare namespace ReactDOM {
    function findDOMNode<E extends Element>(instance: ReactInstance): E;
}

Element comes from lib.es6.d.ts.

@ajafff
Copy link
Contributor

ajafff commented Dec 11, 2017

This is a duplicate of #3540
The cause and the workaround are the same for this issue.

@aaronbeall
Copy link
Author

@ajafff Thanks for the fast response! That thread explains it all and the workaround worked nicely in my case.

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

No branches or pull requests

2 participants