t-comm
Version:
专业、稳定、纯粹的工具库
18 lines (16 loc) • 449 B
TypeScript
/**
* 将函数转成 Promise
* @param {function} promiseLike 任意函数,可以为 Promise
* @returns Promise 函数
* @example
* ```
* const bar = () => 1;
* toPromise(bar()).then(res => console.log(res)); // 1
* function foo() {
* return new Promise(resolve => setTimeout(() => resolve(2), 1000));
* }
* toPromise(foo()).then(res => console.log(res)); // 2
*
* ```
*/
export declare function toPromise(promiseLike: any): any;