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.

var a;<br />

// any<br />

var b: number;<br />

// number<br />

var c = 1;<br />

// number<br />

var d = { x: 1, y: "hello" }; // { x: number; y: string; }<br />

var e: any = "test";<br />

// any<br />

The following is permitted because all declarations of the single variable 'x' associate the same type<br />

(Number) with 'x'.<br />

var x = 1;<br />

var x: number;<br />

if (x == 1) {<br />

var x = 2;<br />

}<br />

In the following example, all five variables are of the same type, '{ x: number; y: number; }'.<br />

interface Point { x: number; y: number; }<br />

var a = { x: 0, y: undefined };<br />

var b: Point = { x: 0, y: undefined };<br />

var c = { x: 0, y: undefined };<br />

var d: { x: number; y: number; } = { x: 0, y: undefined };<br />

var e = { x: 0, y: undefined };<br />

5.1.2 Destructuring Variable Declarations<br />

A destructuring variable declaration introduces zero or more named variables and initializes them with<br />

values extracted from properties of an object or elements of an array.<br />

DestructuringVariableDeclaration:<br />

BindingPattern TypeAnnotation opt Initialiser<br />

BindingPattern:<br />

ObjectBindingPattern<br />

ArrayBindingPattern<br />

ObjectBindingPattern:<br />

{ }<br />

{ BindingPropertyList , opt }<br />

BindingPropertyList:<br />

BindingProperty<br />

BindingPropertyList , BindingProperty<br />

88

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

Saved successfully!

Ooh no, something went wrong!