如何记录已解析的JavaScript Promise值 [英] How to document resolved values of JavaScript promises

查看:40
本文介绍了如何记录已解析的JavaScript Promise值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下代码:

function asyncFoo() {
  return new Promise(function (fulfill, reject) {
    doAsyncStuff(function(err, data) {
      if(err) reject(new Error(err));
      else fulfill(new Bar(data));
    });
  });
}

我如何证明asyncFoo将返回一个Promise,当被满足时将产生一个Bar实例,而在被拒绝时将产生一个Error实例?

How can I document that asyncFoo will return a Promise that, when fulfilled will yield an instance of Bar, and when rejected will yield an instance of Error?

/**
 * @return << Here, what do I have to write? >>
 */
function asyncFoo() { ... }

推荐答案

基于其他一些源代码的注释.

/**
 * @return {Promise.<Bar>}
 */

如何记录JavaScript承诺.

类似的类似问题答案.请注意,答案中没有点.

Similar question with a similar answer. Note the lack of a dot in that answer.

这篇关于如何记录已解析的JavaScript Promise值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆