I am using the jquery.d.ts that comes from the DefinitelyTyped repo (using tsd). It seems to be the "official" jquery typing as the license header says it is created by Microsoft.
Now, I occasionally need to create a deferred object that does not need to pass any arguments to it's .resolve()
or .reject()
methods and I can't figure out how do this with the static typing.
I am currently using a workaround at this point: I am creating the deferred via JQueryDeferred<boolean> dfd = $.Deferred()
and resolve it via dfd.resolve(false)
although I wouldn't really need to pass a boolean value. From the jquery.d.ts file I can only find a JQueryDeferred<T>
declartion, but not a generic one (sth. like JQueryDeferred<void>
but this is not valid TypeScript syntax).
How is it done "the proper way" (TM)?
You have to include the generic <void>
in the call to jQuery.Deferred<void>()
as well.
The following code should compile without errors:
var dfd: JQueryDeferred<void> = jQuery.Deferred<void>();
dfd.resolve();
I don't know why JQueryDeferred<boolean> dfd = $.Deferred()
doesn't cause an error as well though.
By the way: Even if you stay with your workaround, you don't have to pass a boolean to dfd.resolve()
since resolve
's parameter value
is optional (as indicated by the ?
).
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