UPDATE – the context of this question was pre-TypeScript 1.4. Since that version, my first guess has been supported by the language. See the update to the answer.
I can declare f to be a function that accepts a string and returns a string:
var f : (string) => string
And I can declare g to be an array of string:
var g : string[]
How can I declare h to be an array of “function that accepts a string and returns a string”?
My first guess:
var h : ((string) => string)[]
That seems to be a syntax error. If I take away the extra parentheses then it’s a function from string to array of string.
I figured it out. The problem is that the
=>for a function type literal is itself merely syntactic sugar and doesn’t want to compose with[].As the spec says:
So what I want is:
Complete example:
Update:
Judging from this changeset parentheses will be allowed in type declarations in 1.4, so the “first guess” in the question will also be correct:
Further Update It is in 1.4!