'Array of function' type

Topics: General
Jan 25, 2013 at 8:38 AM
Edited Jan 25, 2013 at 8:39 AM

I'm trying to add type information to my array of callbacks. These are stored as an array in a member field:


private callbacks: (r: any) => void [];

What I'm trying to define is that this is an array of (r:any) => void. However, it is being interpreted as a function that takes a single 'any' arguments and returns an array of void.

Obviously I've got my syntax wrong, can someone tell me what the correct format is?


Jan 25, 2013 at 12:46 PM


You can define it like this:

private callbacks: { (r: any): void; }[]; 

Surrounding the function in brackets makes the whole thing an object type with a single call signature that you can create arrays of.

It might be easier to understand if the object type has a named function, written like this:

private callbacks: {
  perform: (r: any) => void;

If you want to read more about this you can check out page 25 and 26 in the spec.

Jan 25, 2013 at 4:18 PM

That's great, many thanks.