简体   繁体   English

flowjs 0.54.0中的新“缺失注释”错误

[英]New “Missing annotation” error in flowjs 0.54.0

After switching to flow 0.54.0 the following code fragment: 切换到流量0.54.0后,以下代码片段:

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 ? 在行中return new Promise(function (resolve, reject) {我似乎无法弄清楚什么是错的?

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. 在这种情况下,它看起来只是undefined ,因为成功案例没有给出任何价值。 You can probably annotate the function that returns this as returning a Promise<void> or something like that to make this error go away. 您可以注释返回此函数的函数作为返回Promise<void>或类似的东西,以使此错误消失。

It is curious that this happens in 0.54 and not before, though. 奇怪的是,这发生在0.54而不是之前。

The Promise<void> annotation in the runKarmaTest function solves this problem: runKarmaTest函数中的Promise<void>注释解决了这个问题:

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 为什么在0.54而不是之前需要这个注释
  • why the flow Type Inference cannot deduce it from the missing parameter in resolve 为什么流Type Inference不能从解决中的缺失参数推断出它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM