TypeScript Language Specification v1.5
TypeScript Language Specification v1.5
TypeScript Language Specification v1.5
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
interface Array {<br />
length: number;<br />
[x: number]: T;<br />
// Other members<br />
}<br />
Array literals (section 4.6) may be used to create values of array types. For example<br />
var a: string[] = ["hello", "world"];<br />
A type is said to be an array-like type if it is assignable (section 3.10.4) to the type any[].<br />
3.3.3 Tuple Types<br />
Tuple types represent JavaScript arrays with individually tracked element types. Tuple types are written<br />
using tuple type literals (section 3.7.5). A tuple type combines a set of numerically named properties with<br />
the members of an array type. Specifically, a tuple type<br />
[ T0, T1, ..., Tn ]<br />
combines the set of properties<br />
{<br />
}<br />
0: T0;<br />
1: T1;<br />
...<br />
n: Tn;<br />
with the members of an array type whose element type is the union type (section 3.4) of the tuple<br />
element types.<br />
Array literals (section 4.6) may be used to create values of tuple types. For example:<br />
var t: [number, string] = [3, "three"];<br />
var n = t[0]; // Type of n is number<br />
var s = t[1]; // Type of s is string<br />
var i: number;<br />
var x = t[i]; // Type of x is number | string<br />
Named tuple types can be created by declaring interfaces that derive from Array and introduce<br />
numerically named properties. For example:<br />
interface KeyValuePair extends Array { 0: K; 1: V; }<br />
28