te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - New "Missing annotation" error in flowjs 0.54.0 - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - New "Missing annotation" error in flowjs 0.54.0 - Stack Overflow

programmeradmin3浏览0评论

After switching to flow 0.54.0 the following code fragment:

function runKarmaTest() {
    const KARMA_CONFIG = {};
    return new Promise(function (resolve, reject) {
        new karma.Server(KARMA_CONFIG, function (exitCode) {
            if (exitCode === 0) {
                resolve();
            } else {
                reject(exitCode);
            }
        }).start();
    });
}

reports the following error:

Error: scripts/runKarma.js:76
               v----------------------------------------
 76:    return new Promise(function (resolve, reject) {
 77:            new karma.Server(KARMA_CONFIG, function (exitCode) {
 78:                    if (exitCode === 0) {
...:
 84:    });
        -^ type parameter `R` of constructor call. Missing annotation

in the line return new Promise(function (resolve, reject) { and I cannot seem to figure out what's wrong ?

After switching to flow 0.54.0 the following code fragment:

function runKarmaTest() {
    const KARMA_CONFIG = {};
    return new Promise(function (resolve, reject) {
        new karma.Server(KARMA_CONFIG, function (exitCode) {
            if (exitCode === 0) {
                resolve();
            } else {
                reject(exitCode);
            }
        }).start();
    });
}

reports the following error:

Error: scripts/runKarma.js:76
               v----------------------------------------
 76:    return new Promise(function (resolve, reject) {
 77:            new karma.Server(KARMA_CONFIG, function (exitCode) {
 78:                    if (exitCode === 0) {
...:
 84:    });
        -^ type parameter `R` of constructor call. Missing annotation

in the line return new Promise(function (resolve, reject) { and I cannot seem to figure out what's wrong ?

Share Improve this question edited Sep 2, 2017 at 12:40 doberkofler asked Sep 1, 2017 at 8:53 doberkoflerdoberkofler 10.4k22 gold badges88 silver badges146 bronze badges 2
  • which version of Flow were you previously using? 0.52 or 0.53 – Taras Yaremkiv Commented Sep 2, 2017 at 11:26
  • I just upgrade from 0.53.1 – doberkofler Commented Sep 2, 2017 at 12:35
Add a ment  | 

2 Answers 2

Reset to default 11

It looks like the thing it wants to know is the type of value wrapped by the promise. In this case it looks like it's just undefined, since the success case doesn't give any value. You can probably annotate the function that returns this as returning a Promise<void> or something like that to make this error go away.

It is curious that this happens in 0.54 and not before, though.

The Promise<void> annotation in the runKarmaTest function solves this problem:

function runKarmaTest(): Promise<void> {
    const KARMA_CONFIG = {};
    return new Promise(function (resolve, reject) {
        new karma.Server(KARMA_CONFIG, function (exitCode) {
            if (exitCode === 0) {
                resolve();
            } else {
                reject(exitCode);
            }
        }).start();
    });
}

I'm still not sure:

  • why this annotation is needed in 0.54 and not before
  • why the flow Type Inference cannot deduce it from the missing parameter in resolve
发布评论

评论列表(0)

  1. 暂无评论