How would you declare an array of callbacks in TypeScript?
A single callback looks like this:
var callback:(param:string)=>void = function(param:string) {};
So an array of callbacks should look like this:
var callback:(param:string)=>void[] = [];
However, that creates ambiguity, since I could mean an array of callbacks, or a single callback which returns an array of voids.
In the TypeScript playground, it thinks it is an array of voids. So, my next though was to wrap it in parentheses:
var callback:((param:string)=>void)[] = [];
But that doesn't work either.
Any other ideas?
You'll need to use the full type literal syntax form, like so:
var callback:{(param:string): void;}[] = [];
This is sort of ugly; if you like you can make a name for it first:
interface fn {
(param: string): void;
}
var callback2: fn[] = [];
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