23.06.2015 Views

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

of the object literal includes a numeric index signature with the union type of the types of the numerically<br />

named properties (section 3.8.4) declared in the object literal, or the Undefined type if the object literal<br />

declares no numerically named properties.<br />

4.6 Array Literals<br />

Array literals are extended to support the spread (...) operator.<br />

ElementList: ( Modified )<br />

Elision opt AssignmentExpression<br />

Elision opt SpreadElement<br />

ElementList , Elision opt AssignmentExpression<br />

ElementList , Elision opt SpreadElement<br />

SpreadElement:<br />

... AssignmentExpression<br />

An array literal<br />

[ expr1, expr2, ..., exprN ]<br />

denotes a value of an array type (section 3.3.2) or a tuple type (section 3.3.3) depending on context.<br />

Each element expression in a non-empty array literal is processed as follows:<br />

<br />

<br />

<br />

If the array literal contains no spread elements, and if the array literal is contextually typed<br />

(section 4.19) by a type T and T has a property with the numeric name N, where N is the index of<br />

the element expression in the array literal, the element expression is contextually typed by the<br />

type of that property.<br />

Otherwise, if the array literal is contextually typed by a type T with a numeric index signature, the<br />

element expression is contextually typed by the type of the numeric index signature.<br />

Otherwise, the element expression is not contextually typed.<br />

The resulting type an array literal expression is determined as follows:<br />

<br />

<br />

<br />

<br />

If the array literal is empty, the resulting type is an array type with the element type Undefined.<br />

Otherwise, if the array literal contains no spread elements and is contextually typed by a tuple-like<br />

type (section 3.3.3), the resulting type is a tuple type constructed from the types of the element<br />

expressions.<br />

Otherwise, if the array literal contains no spread elements and is an array assignment pattern in a<br />

destructuring assignment (section 4.17.1), the resulting type is a tuple type constructed from the<br />

types of the element expressions.<br />

Otherwise, the resulting type is an array type with an element type that is the union of the types<br />

of the non-spread element expressions and the numeric index signature types of the spread<br />

element expressions.<br />

60

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!