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.

the type Any.<br />

In the example<br />

function f({ a, b = "hello", c = 1 }) { ... }<br />

the implied type of the binding pattern in the function's parameter is '{ a: any; b?: string; c?: number; }'.<br />

Since the parameter has no type annotation, this becomes the type of the parameter.<br />

In the example<br />

var [a, b, c] = [1, "hello", true];<br />

the array literal initializer expression is contextually typed by the implied type of the binding pattern,<br />

specifically the tuple type '[any, any, any]'. Because the contextual type is a tuple type, the resulting type<br />

of the array literal is the tuple type '[number, string, boolean]', and the destructuring declaration thus<br />

gives the types number, string, and boolean to a, b, and c respectively.<br />

5.2 If, Do, and While Statements<br />

Expressions controlling 'if', 'do', and 'while' statements can be of any type (and not just type Boolean).<br />

5.3 For Statements<br />

Variable declarations in 'for' statements are extended in the same manner as variable declarations in<br />

variable statements (section 5.1).<br />

5.4 For-In Statements<br />

In a 'for-in' statement of the form<br />

for (v in expr) statement<br />

v must be an expression classified as a reference of type Any or the String primitive type, and expr must<br />

be an expression of type Any, an object type, or a type parameter type.<br />

In a 'for-in' statement of the form<br />

for (var v in expr) statement<br />

v must be a variable declaration without a type annotation that declares a variable of type Any, and expr<br />

must be an expression of type Any, an object type, or a type parameter type.<br />

92

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

Saved successfully!

Ooh no, something went wrong!