-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule proposal: prefer-instanceof-element
#1574
Comments
I think the rule scope and name should be more narrow. This will also most likely get solved in TypeScript at some point: microsoft/TypeScript#38839 |
prefer-instanceof
prefer-instanceof-element
How about
I'm aware of that but it will probably take forever. And there are benefits outside TS too. |
I would name it |
What are the non-TS benefits? |
Checking the type of an element via
element.tagName === 'name'
doesn't give you type guard and you have to use optional chain (or!
a.k.a. Typescript's non-null assertion operator) if the element can beundefined
ornull
.Some elements have a corresponding JavaScript interface (e.g.
HTMLImageElement
for<img>
), one can also useinstanceof
to check the element type without the aforementioned shortcomings.An real life example is:
574d442
(#5036)Fail
Pass
The text was updated successfully, but these errors were encountered: