Flow: Getting fulfillment type from Promise?

Created on 29 Mar 2018  路  3Comments  路  Source: facebook/flow

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.

Most helpful comment

You can use a helper type like this:

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

All 3 comments

+1

+1

You can use a helper type like this:

type UnwrapPromise<T> = $Call<<T>(Promise<T>) => T, T>;
Was this page helpful?
0 / 5 - 0 ratings