TypeScript and void Q promises

What is the correct way to use Q promises with TypeScript 1.6 if they are not valid? That is, they do not represent value. For example:

return Q.Promise<void>((resolve,reject) => {
    resolve();
}

or

let deferred = Q.defer<void>();
deferred.resolve();
return deferred.promise;

The call resolve()causes an error:

Supplied parameters do not match any signature of call target
(parameter) resolve: (val: void | Q.IPromise<void>) => void

Please note that the following works:

let deferred = Q.defer<string>();
deferred.resolve("Hello World");
return deferred.promise;

Perhaps this is a bug in DefinitelyTyped (updated August 17, 2015 at the time of this writing), or am I pointing this out incorrectly?

+4
source share
2 answers

For Q with TS1.6, I ended up using:

return Q.Promise<void>((resolve,reject) => {
    resolve(null);
}
+1
source

If there is no return value or I do not need to return the value, I used ...

return Q.Promise<any>((resolve, reject) => {
  resolve();
}
+1
source

Source: https://habr.com/ru/post/1609669/


All Articles