new Promise<boolean>((res, rej) => {
res(true);
})
.then(res => {
console.log(res);
return false;
})
.then(res => {
console.log(res);
return true;
})
.then(res => {
console.log(res);
})
.catch(error => {
console.log('ERROR:', error.message);
});
type AsyncReturnType<T extends (...args: any) => any> =
T extends (...args: any) => Promise<infer U> ? U :
T extends (...args: any) => infer U ? U :
any
//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