Rule proposal: `no-instanceof-error`
See original GitHub issueDisallow instanceof Error
checks.
Fail
const isError = foo instanceof Error;
Pass
const isError = Object.prototype.toString.call(foo) === '[object Error]'
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Why is instanceof in TypeScript not working for inherited class?
So it seems it detects it's an instance of Error but not an instance of ErrorForbidden even though that's how I've created it....
Read more >Java “instanceOf”: Why And How To Avoid It In Code - Armedia
The java “instanceof” operator is used to test whether the object is an instance of the specified type (class or subclass or interface)....
Read more >Exception types should not be tested using "instanceof" in ...
Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells ... Exception types should not be tested using "instanceof" in catch blocks....
Read more >TypeError: invalid 'instanceof' operand 'x' - JavaScript | MDN
The JavaScript exception "invalid 'instanceof' operand" occurs when the right-hand side operands of the instanceof operator isn't used with ...
Read more >Wrong compiler error reported for generic instanceof pattern ...
Right in the code area of the proposed change, a comment gives a hint where the rule discussed in comment 5 comes from:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This rule is accepted.
Correct