Back to Functions

isError

lang

Checks if value is an Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, or URIError object.

Installation

Import
import { isError } from '@tulx/utils';

Source Code

Implementation
/**
 * Checks if value is an Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, or URIError object.
 *
 * @param value - The value to check.
 * @returns Returns true if value is an error object, else false.
 *
 * @example
 * ```ts
 * isError(new Error); // true
 * isError(Error); // false
 * ```
 */
export function isError(value: unknown): value is Error {
  return value instanceof Error;
}

Example

import { isError } from '@tulx/utils';

isError(new Error); // true
isError(Error); // false

Related Functions