Type guard for Error instances.
This function checks if a value is an instance of the Error class or any of its subclasses. It's useful for error handling and type narrowing when working with unknown values that might be errors.
Value to test
true if the value is an Error instance, false otherwise
true
false
try { throw new TypeError('Something went wrong');} catch (err) { if (isError(err)) { // err is now typed as Error console.log(err.message); }} Copy
try { throw new TypeError('Something went wrong');} catch (err) { if (isError(err)) { // err is now typed as Error console.log(err.message); }}
Type guard for Error instances.
This function checks if a value is an instance of the Error class or any of its subclasses. It's useful for error handling and type narrowing when working with unknown values that might be errors.