03.10.2012 Views

TypeScript Language Specification

TypeScript Language Specification

TypeScript Language Specification

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.

NOTE: The <strong>TypeScript</strong> compiler currently implements an experimental form of enum types. We expect the<br />

final language to support enum types, but not in the form they are currently implemented.<br />

NOTE: <strong>TypeScript</strong> currently doesn’t support Generics, but we expect to include them in the final language.<br />

Since <strong>TypeScript</strong>’s static type system has no run-time manifestation, Generics will be based on “type erasure”<br />

and intended purely as a conduit for expressing parametric type relationships in interfaces, classes, and<br />

function signatures.<br />

3.1 The Any Type<br />

The Any type is used to represent any JavaScript value. A value of the Any type supports the same<br />

operations as a value in JavaScript and no static type checking is performed for operations on Any values.<br />

Specifically, properties of any name can be accessed through an Any value and Any values can be called<br />

as functions or constructors with any argument list.<br />

The any keyword references the Any type. In general, in places where a type is not explicitly provided and<br />

<strong>TypeScript</strong> cannot infer one, the Any type is assumed.<br />

The Any type is a supertype of all types.<br />

Some examples:<br />

var x: any; // Explicitly typed<br />

var y; // Same as y: any<br />

var z: { a; b; }; // Same as z: { a: any; b: any; }<br />

function f(x) { // Same as f(x: any): void<br />

console.log(x);<br />

}<br />

3.2 Primitive Types<br />

The primitive types are the Number, Boolean, String, Null, and Undefined types.<br />

3.2.1 The Number Type<br />

The Number primitive type corresponds to the similarly named JavaScript primitive type and represents<br />

double-precision 64-bit format IEEE 754 floating point values.<br />

The number keyword references the Number primitive type and numeric literals may be used to write<br />

values of the Number primitive type.<br />

For purposes of determining type relationships (section 3.6) and accessing properties (section 4.10), the<br />

Number primitive type behaves as an object type with the same properties as the global interface type<br />

‘Number’ plus its own unique brand.<br />

Some examples:<br />

18

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

Saved successfully!

Ooh no, something went wrong!