es-toolkit/docs/reference/predicate/isError.md
hyesung oh ea01c77121
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run
feat(isError): append isError (#579)
* feat: add isError to predicate

Co-authored-by: leeminhee119 <mhl98@dgu.ac.kr>

* test: isError


Co-authored-by: leeminhee119 <mhl98@dgu.ac.kr>

* docs: isError


Co-authored-by: leeminhee119 <mhl98@dgu.ac.kr>

* feat: isError at compat


Co-authored-by: leeminhee119 <mhl98@dgu.ac.kr>

* feat: export to compat

* fix: format

Co-authored-by: leeminhee119 <mhl98@dgu.ac.kr>

---------

Co-authored-by: leeminhee119 <mhl98@dgu.ac.kr>
2024-09-23 11:27:08 +09:00

560 B

isError

Check if the given value is an Error object.

This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to Error.

Signature

function isError(value: unknown): value is Error;

Parameters

  • value(unknown): The value to test if it is an Error object.

Returns

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

Examples

isError(new Error()); // true
isError('error'); // false
isError({ name: 'Error', message: '' }); // false