For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/predicate/isError.md.

isError es-toolkit

Checks if a value is an Error object.

const result = isError(value);

Usage

isError(value)

Use isError when you want to check if a value is an Error object. It can be used as a type guard in TypeScript to narrow the value's type to Error. Particularly useful in try-catch blocks or API response processing.

import { isError } from 'es-toolkit/predicate';

// Checking Error objects
isError(new Error('Something went wrong')); // true
isError(new TypeError('Type error')); // true

// Distinguishing from other types
isError('error'); // false
isError({ name: 'Error', message: 'Custom error' }); // false

When used as a type guard in TypeScript, the value's type is narrowed.

function handleError(value: unknown) {
  if (isError(value)) {
    // value is narrowed to Error
    console.log(`Error occurred: ${value.message}`);
    return value.name;
  }
  return 'Not an error';
}

Parameters

valueunknownrequired

The value to check if it's an Error object.

Returns

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

value is Error
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.