question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `no-instanceof-error`

See original GitHub issue

Disallow instanceof Error checks.

Fail

const isError = foo instanceof Error;

Pass

const isError = Object.prototype.toString.call(foo) === '[object Error]'

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Jul 17, 2020

This rule is accepted.

1reaction
sindresorhuscommented, May 13, 2020

Correct

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found