Promise<T>的定义?

来源:5-11 获取响应数据 - 需求分析+实现

慕粉6137024

2021-03-12

lib.dom.ts找到了,但没看到Interface Promise的定义
像这种typescript预置的接口有必要去学习吗?

写回答

1回答

ustbhuangyi

2021-03-12

在 lib.es5.d.ts 中有定义

interface Promise<T> {
   /**
    * Attaches callbacks for the resolution and/or rejection of the Promise.
    * @param onfulfilled The callback to execute when the Promise is resolved.
    * @param onrejected The callback to execute when the Promise is rejected.
    * @returns A Promise for the completion of which ever callback is executed.
    */
   then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;

   /**
    * Attaches a callback for only the rejection of the Promise.
    * @param onrejected The callback to execute when the Promise is rejected.
    * @returns A Promise for the completion of the callback.
    */
   catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
}

建议用到了进去查一查就好了

0
1
慕粉6137024
OK!老师回复的速度真快~超赞
2021-03-12
共1条回复

下一代前端开发语言 TypeScript从零重构axios

课程从零开始重构功能完整的JS库,是学习造轮子的不二之选!

2629 学习 · 877 问题

查看课程