This project is read-only.

arrays of functions

Topics: General
Oct 6, 2012 at 12:20 AM

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 1:10 AM
Edited Oct 6, 2012 at 1: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 8:00 AM
Edited Oct 6, 2012 at 8: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 = [];