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.

Similarly, an array destructuring declaration of the form<br />

var [x, y, z = 10] = getSomeArray();<br />

is rewritten to the simple variable declarations<br />

var _a = getSomeArray(),<br />

x = _a[0],<br />

y = _a[1],<br />

_b = _a[2],<br />

z = _b === void 0 ? 10 : _b;<br />

Combining both forms of destructuring, the example<br />

var { x, p: [y, z = 10] = getSomeArray() } = getSomeObject();<br />

is rewritten to<br />

var _a = getSomeObject(),<br />

x = _a.x,<br />

_b = _a.p,<br />

_c = _b === void 0 ? getSomeArray() : _b,<br />

y = _c[0],<br />

_d = _c[1],<br />

z = _d === void 0 ? 10 : _d;<br />

5.1.3 Implied Type<br />

A variable, parameter, binding property, or binding element declaration that specifies a binding pattern<br />

has an implied type which is determined as follows:<br />

<br />

<br />

<br />

If the declaration specifies an object binding pattern, the implied type is an object type with a set<br />

of properties corresponding to the specified binding property declarations. The type of each<br />

property is the type implied by its binding property declaration, and a property is optional when<br />

its binding property declaration specifies an initializer expression.<br />

If the declaration specifies an array binding pattern without a rest element, the implied type is a<br />

tuple type with elements corresponding to the specified binding element declarations. The type<br />

of each element is the type implied by its binding element declaration.<br />

If the declaration specifies an array binding pattern with a rest element, the implied type is an<br />

array type with an element type of Any.<br />

The implied type of a binding property or binding element declaration is<br />

<br />

<br />

the type of the declaration's initializer expression, if any, or otherwise<br />

the implied type of the binding pattern specified in the declaration, if any, or otherwise<br />

91

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

Saved successfully!

Ooh no, something went wrong!