This can be done using conditional types like so:

const x = async (y) => {
return 1
}

type Unpacked<T> =
T extends Promise<infer U> ? U :
T;

export type T = Unpacked<ReturnType<typeof x>> // number

Hopefully that’s what you’re after! If you want to read a bit more about how this works, check out the Conditional Types section of here: http://www.typescriptlang.org/docs/handbook/advanced-types.html

    Curtis Tate Wilkinson

    Written by

    Software Developer. Twitter: @curtytate