In TypeScript, what is the difference between Array
and any[]
? Does Array refer to dynamically sized arrays (during compile-time, of course) and
Spec section 3.5.4 specifies their relationship:
An array type of the form
ElementType[]
is equivalent to an object type with the index signature[index: number]: ElementType
plus a set of members equivalent to the global interface typeArray
where all occurrences of the magic_element
type are replaced withElementType
.
Not being able to assign [[], []]
or []
to Array
is a bug.
There is no notion of a "statically-sized" array in TypeScript. They're all talking about the same underlying JavaScript array (which is dynamically sized):
var x = [1, 2];
x.push(3);
x[13] = 5;