Skip to content

Commit

Permalink
Add isPromiseLike helper
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Nov 22, 2024
1 parent 578d45f commit bcf9a87
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,8 @@ export function coerceError(err: unknown): Error & { code?: unknown } {
return new Error(message, { cause: err });
}
}

export function isPromiseLike<T>(v: PromiseLike<T> | T): v is PromiseLike<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return v != null && typeof (v as any).then === "function";
}

0 comments on commit bcf9a87

Please sign in to comment.