diff --git a/packages/eventual-send/src/index.d.ts b/packages/eventual-send/src/index.d.ts index 0b3064e267..1515391a8e 100644 --- a/packages/eventual-send/src/index.d.ts +++ b/packages/eventual-send/src/index.d.ts @@ -257,7 +257,7 @@ interface EProxy { * E.when(x, res, rej) is equivalent to * HandledPromise.resolve(x).then(res, rej) */ - readonly when: ( + readonly when: >( x: T, onfulfilled?: (value: Awaited) => ERef, onrejected?: (reason: any) => ERef, diff --git a/packages/eventual-send/src/index.test-d.ts b/packages/eventual-send/src/index.test-d.ts index 74aca3b523..76630cce35 100644 --- a/packages/eventual-send/src/index.test-d.ts +++ b/packages/eventual-send/src/index.test-d.ts @@ -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 = Promise.resolve('remote'); +E.when(Promise.all([aPromise, onePromise, remoteString])).then( + ([str, num, remote]) => { + expectType(str); + expectType(num); + expectType(remote); + }, +); +E.when( + Promise.all([aPromise, onePromise, remoteString]), + ([str, num, remote]) => { + expectType(str); + expectType(num); + expectType(remote); + return { something: 'new' }; + }, +).then(result => { + expectType<{ something: string }>(result); +});