flow icon indicating copy to clipboard operation
flow copied to clipboard

Getting fulfillment type from Promise?

Open bgdavidx opened this issue 8 years ago • 3 comments

Let's say I have a function like such:

async function f() { return 1 } // returns Promise<number>

I can get the type it returns via $Call:

type ReturnType = $Call<typeof f> // type is Promise<number>

but how can I get the resolved type of the Promise? In this case it is number.

bgdavidx avatar Mar 29 '18 02:03 bgdavidx

+1

manfredxu99 avatar Mar 29 '18 02:03 manfredxu99

+1

brad-alexander avatar Mar 29 '18 02:03 brad-alexander

You can use a helper type like this:

type UnwrapPromise<T> = $Call<<T>(Promise<T>) => T, T>;

vkurchatkin avatar Mar 29 '18 07:03 vkurchatkin