23.06.2015 Views

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

TypeScript Language Specification v1.5

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The following example illustrates the concept of an instance type:<br />

class G {<br />

// Introduce type parameter T<br />

self: G;<br />

// Use T as type argument to form instance type<br />

f() {<br />

this.self = this; // self and this are both of type G<br />

}<br />

}<br />

3.7 Specifying Types<br />

Types are specified either by referencing their keyword or name, or by writing object type literals, array<br />

type literals, tuple type literals, function type literals, constructor type literals, or type queries.<br />

Type:<br />

PrimaryOrUnionType<br />

FunctionType<br />

ConstructorType<br />

PrimaryOrUnionType:<br />

PrimaryType<br />

UnionType<br />

PrimaryType:<br />

ParenthesizedType<br />

PredefinedType<br />

TypeReference<br />

ObjectType<br />

ArrayType<br />

TupleType<br />

TypeQuery<br />

ParenthesizedType:<br />

( Type )<br />

Parentheses are required around union, function, or constructor types when they are used as array<br />

element types, and parentheses are required around function or constructor types in union types. For<br />

example:<br />

(string | number)[]<br />

((x: string) => string) | ((x: number) => number)<br />

The different forms of type notations are described in the following sections.<br />

35

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

Saved successfully!

Ooh no, something went wrong!