Skip to content

isError (Lodash Compatibility) ​

Use es-toolkit's isError instead

This isError function operates slowly due to complex handling for Lodash compatibility.

Use the faster and more modern es-toolkit's isError instead.

Checks if a value is an Error object.

typescript
const result = isError(value);

Reference ​

isError(value) ​

Use isError when you want to type-safely check if a value is an Error object. It also works as a type guard in TypeScript.

typescript
import { isError } from 'es-toolkit/compat';

// Error object checking
isError(new Error()); // true
isError(new TypeError('Type error')); // true
isError(new ReferenceError('Reference error')); // true

// Custom errors that inherit from Error
class CustomError extends Error {}
isError(new CustomError()); // true

// Other types return false
isError('Error'); // false
isError({ name: 'Error', message: 'Something went wrong' }); // false
isError({}); // false
isError(null); // false
isError(undefined); // false

Parameters ​

  • value (unknown): The value to check if it's an Error object.

Returns ​

(value is Error): Returns true if the value is an Error object, false otherwise.

Released under the MIT License.