* Checks if a given value is an Error-like object. * * This type guard checks if the value is an instance of `Error` or if it's an object * with `name` and `message` properties. This is useful for identifying error-like * objects that may not be direct instances of `Error` (e.g., from RxJs). *
(value: unknown)
| 20 | * @returns `true` if the value is an Error-like object, `false` otherwise. |
| 21 | */ |
| 22 | function isError(value: unknown): value is Error { |
| 23 | return ( |
| 24 | value instanceof Error || |
| 25 | (typeof value === 'object' && value !== null && 'name' in value && 'message' in value) |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Asserts that a given value is an Error-like object. |