eslint-plugin-unicorn: Rule proposal: `prefer-error-iserror`
Disallow instanceof Error checks.
Fail
const isError = foo instanceof Error;
Pass
const isError = Object.prototype.toString.call(foo) === '[object Error]'
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 18 (8 by maintainers)
Is it though? If I load the same library in 2 realms I have the same issue. It’s just that built-ins are more common.
instanceofis never safe, it’s just easy to use until you have to check something cross-realm.Example
I think if you want to add this rule it should be a configurable
no-instanceofand the default toErrorand whatever you encounter the most often.Suggest hold this for
Error.isErrorThis rule is accepted.
Correct
Sounds good
Yeah, I think we should just do
Errorfor now.Erroris usually the problematic global.