Skip to content

Commit 1222e4e

Browse files
committed
better awaited??
1 parent 429fb89 commit 1222e4e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/core/src/utils/handleCallbackErrors.ts

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

33
/* eslint-disable */
4-
// Vendor this in to be TS 3.8 compatible
5-
type Awaited<T> = T extends null | undefined
4+
// Vendor "Awaited" in to be TS 3.8 compatible
5+
type AwaitedPromise<T> = T extends null | undefined
66
? T // special case for `null | undefined` when not in `--strictNullChecks` mode
77
: 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
88
? 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
9+
? V // normally this would recursively unwrap, but this is not possible in TS3.8
1010
: never // the argument to `then` was not callable
1111
: T; // non-object or non-thenable
1212
/* eslint-enable */
1313

1414
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15-
export function handleCallbackErrors<Fn extends () => Promise<any>, PromiseValue = Awaited<ReturnType<Fn>>>(
15+
export function handleCallbackErrors<Fn extends () => Promise<any>, PromiseValue = AwaitedPromise<ReturnType<Fn>>>(
1616
fn: Fn,
1717
onError: (error: unknown) => void,
1818
onFinally?: () => void,
@@ -44,7 +44,7 @@ export function handleCallbackErrors<
4444
fn: Fn,
4545
onError: (error: unknown) => void,
4646
onFinally: () => void = () => {},
47-
onSuccess: (result: ValueType | Awaited<ValueType>) => void = () => {},
47+
onSuccess: (result: ValueType | AwaitedPromise<ValueType>) => void = () => {},
4848
): ValueType {
4949
let maybePromiseResult: ReturnType<Fn>;
5050
try {
@@ -68,7 +68,7 @@ function maybeHandlePromiseRejection<MaybePromise>(
6868
value: MaybePromise,
6969
onError: (error: unknown) => void,
7070
onFinally: () => void,
71-
onSuccess: (result: MaybePromise | Awaited<MaybePromise>) => void,
71+
onSuccess: (result: MaybePromise | AwaitedPromise<MaybePromise>) => void,
7272
): MaybePromise {
7373
if (isThenable(value)) {
7474
// @ts-expect-error - the isThenable check returns the "wrong" type here

0 commit comments

Comments
 (0)