i'm using Typescript and jQuery Promises and I am experiencing an error with the following code:
var promiseOne = this.myFunc(1);
var promiseTwo = this.myFunc(2);
$.when(promiseOne, promiseTwo).then((valFromPromiseOne: number, valFromPromiseTwo: number) => //Error here (see below)
{
//Use both return values of the promises...
});
myFunc(value: number): JQueryPromise<number>
{
var dfd = $.Deferred();
setTimeout(function ()
{
dfd.resolve(value);
}, 1000);
return dfd.promise();
}
The error I'm getting is:
Error 5 Supplied parameters do not match any signature of call target:
Call signatures of types '(valFromPromiseOne: number, valFromPromiseTwo: number) => void' and '(value: any) => {}' are incompatible:
Call signature expects 1 or fewer parameters.
I want the function to execute only when both Promises are resolved.
Am I doing somenthing wrong? Is there a different way to achieve what I want?
Thanks
Finally found out the way to do it. The second parameter has to be optional.
$.when(promiseOne, promiseTwo).then((valFromPromiseOne: number, valFromPromiseTwo?: number) => //valFromPromiseTwo has to be optional
{
//Use both return values of the promises...
});
After this change, it is working fine.
Not sure if it is the right way. But it worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With