Skip to content

Commit bc7c0ff

Browse files
authored
(fix) awaited type of promise or plain value (#439)
When awaiting the value of a type like Promise<string> | null, the type wouldn't match PromiseLike. Hence the awaited value would still be Promise<string> | null and not string | null. Reducing it to one type declaration and using a conditional type to infer the awaited type should do the trick.
1 parent cf4eb70 commit bc7c0ff

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

packages/svelte2tsx/svelte-shims.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,10 @@ declare function __sveltets_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 |
154154
declare function __sveltets_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
155155
declare function __sveltets_unionType(...types: any[]): any;
156156

157-
declare function __sveltets_awaitThen<T>(
158-
promise: PromiseLike<T>,
159-
onfulfilled: (value: T) => any,
160-
onrejected?: (value: any) => any
161-
): any;
162157
declare function __sveltets_awaitThen<T>(
163158
promise: T,
164-
onfulfilled: (value: T) => any,
165-
onrejected?: (value: never) => any
159+
onfulfilled: (value: T extends PromiseLike<infer U> ? U : T) => any,
160+
onrejected?: (value: T extends PromiseLike<any> ? any : never) => any
166161
): any;
167162

168163
declare function __sveltets_each<T>(

0 commit comments

Comments
 (0)