Skip to content

Commit

Permalink
fix: typedef default onfulfilled handler for E.when
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 7, 2022
1 parent 54e79eb commit 5a470a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eventual-send/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ interface EProxy {
* E.when(x, res, rej) is equivalent to
* HandledPromise.resolve(x).then(res, rej)
*/
readonly when: <T, U>(
readonly when: <T, U = Awaited<T>>(
x: T,
onfulfilled?: (value: Awaited<T>) => ERef<U>,
onrejected?: (reason: any) => ERef<U>,
Expand Down
23 changes: 23 additions & 0 deletions packages/eventual-send/src/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@ const foo2 = async (a: FarRef<{ bar(): string; baz: number }>) => {
// @ts-expect-error - calling directly is valid but not yet in the typedef
a.bar;
};

// when
const aPromise = Promise.resolve('a');
const onePromise = Promise.resolve(1);
const remoteString: ERef<string> = Promise.resolve('remote');
E.when(Promise.all([aPromise, onePromise, remoteString])).then(
([str, num, remote]) => {
expectType<string>(str);
expectType<number>(num);
expectType<string>(remote);
},
);
E.when(
Promise.all([aPromise, onePromise, remoteString]),
([str, num, remote]) => {
expectType<string>(str);
expectType<number>(num);
expectType<string>(remote);
return { something: 'new' };
},
).then(result => {
expectType<{ something: string }>(result);
});

0 comments on commit 5a470a5

Please sign in to comment.