> It would be nice to have Array literal syntax declare it's ArrayType
> before the declaration of the array.
> For example:
> 1. var x : Array<String> = [ "foo", "bar", document.title,
> getAnotherString() ];
Array is not a parameterized type. If it were, the syntax would be
Array must be backward compatible, so if it were changed to be
parameterized by element type, then it would have to default to
Array.<*> when used without a parameter list. But we don't have
default type parameters, and anyway a type-parametric Array reference
without the actual type param list would be ambiguous: should it mean
Array.<*> by default, or Array, with instantiation using an actual
type param happening later: let A = Array; type TA = A.<T> ?
So there's no good way to overload Array as you want.
Also, Array is closer to Object than to any homogenous tuple or
vector type. Hence the separate
> Is the former syntax (or some variant thereof) going to be available?
No, as explained above. But what you might want is:
let x : [string] = ["foo", "bar", document.title, getAnotherString()];
* let trumps var in any hand ;-)
* string is the type of "foo", String is the dynamic class for
wrappers, as in ES1-3 that shares its .prototype with string
instances as well as String instances, via the usual prototype-based
delegation. Prefer string in general.
* [string] is a type expression denoted a structural array type.