TypeScript Callback Array

How would you declare a callback array in TypeScript?

One callback is as follows:

var callback:(param:string)=>void = function(param:string) {}; 

So the callback array should look like this:

 var callback:(param:string)=>void[] = []; 

However, this creates ambiguity, because I can keep in mind an array of callbacks or one callback that returns an array of voids.

At TypeScript, she thinks it's an array of voids. So my next one though was to enclose it in parentheses:

 var callback:((param:string)=>void)[] = []; 

But that doesn't work either.

Any other ideas?

+6
source share
1 answer

You will need to use the full syntax form, for example:

 var callback:{(param:string): void;}[] = []; 

It's not beautiful; if you like, you can first write the name:

 interface fn { (param: string): void; } var callback2: fn[] = []; 
+10
source

All Articles