arrays of functions

Topics: General
Oct 5, 2012 at 11:20 PM

i'm trying to get my head around the whole function/object type literal duality. and it's not working.
how do i write the type of an array of functions? why doesn't this work?

var rg:{():void}[] = [function ():void { }];

Oct 6, 2012 at 12:10 AM
Edited Oct 6, 2012 at 12:12 AM


var rg: { (): void; }[] = ...;

Compiler says you're missing a semicolon. Add one right after 'void' and before the closing brace '}'.

When you use the braces to define an 'object type literal', you put within the braces a semi-colon-separated list of 'signatures'.

This part of the grammar is on p23 of the spec [3.5.3 Object Type Literals].

Oct 6, 2012 at 7:00 AM
Edited Oct 6, 2012 at 7:01 AM

slight correction Alex...

var rg: { (): void; }[] = [];


You have to keep in mind that all type intformation is going to drop out os it should read like valid JavaScript if you remove the typing.  That means the above would resolve to:

var rg = [];