Skip to content

Commit 0a7f229

Browse files
committed
vendor type in
1 parent c29ed70 commit 0a7f229

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/core/src/utils/handleCallbackErrors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { isThenable } from '../utils/is';
22

3+
/* eslint-disable */
4+
// Vendor this in to be TS 3.8 compatible
5+
type Awaited<T> = T extends null | undefined
6+
? T // special case for `null | undefined` when not in `--strictNullChecks` mode
7+
: T extends object & { then(onfulfilled: infer F, ...args: infer _): any } // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
8+
? F extends (value: infer V, ...args: infer _) => any // if the argument to `then` is callable, extracts the first argument
9+
? Awaited<V> // recursively unwrap the value
10+
: never // the argument to `then` was not callable
11+
: T; // non-object or non-thenable
12+
/* eslint-enable */
13+
314
// eslint-disable-next-line @typescript-eslint/no-explicit-any
415
export function handleCallbackErrors<Fn extends () => Promise<any>, PromiseValue = Awaited<ReturnType<Fn>>>(
516
fn: Fn,

0 commit comments

Comments
 (0)