Skip to content

Commit 018c8d4

Browse files
committed
feat: use Error.isError when available
1 parent 1af3d1a commit 018c8d4

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/error.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface ErrorConstructor {
2+
isError(error: unknown): error is Error;
3+
}

src/is-error.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const getPrototypeOf = Object.getPrototypeOf;
2727
const ERROR_TYPE = '[object Error]';
2828

2929
export function isError(a: unknown): a is Error {
30+
if (typeof Error.isError === 'function') {
31+
return Error.isError(a);
32+
}
33+
3034
if (a instanceof Error) {
3135
return true;
3236
}

0 commit comments

Comments
 (0)