type AsyncReturnType<T extends (...args: any) => any> =
T extends (...args: any) => Promise<infer U> ? U :
T extends (...args: any) => infer U ? U :
any
function promiseOne() {
return Promise.resolve(1)
}
const promisedOne = promiseOne()
// note PromiseLike instead of Promise, this lets it work on any thenable
type ThenArg<T> = T extends PromiseLike<infer U> ? U : T
type PromiseOneThenArg = ThenArg<typeof promisedOne> // => number
// or
type PromiseOneThenArg2 = ThenArg<ReturnType<typeof promiseOne>> // => number
//return from promise
type promiseReturn<T extends Promise<unknown>> = T extends Promise<infer type>
? type extends Promise<unknown>
? promiseReturn<type>
: type
: never;
type prom = promiseReturn<Promise<string>>; //string
type prom_2 = promiseReturn<Promise<Promise<string>>>; //string