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 ?
- 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
2 Answers
Reset to default 11It 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