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.

Type aliases are referenced using type references (3.7.2). Writing a reference to a type alias has exactly<br />

the same effect as writing the aliased type itself.<br />

The Identifier of a type alias declaration may not be one of the predefined type names (section 3.7.1).<br />

It is an error for the type specified in a type alias to depend on that type alias. Types have the following<br />

dependencies:<br />

<br />

<br />

<br />

<br />

<br />

<br />

A type alias directly depends on the type it aliases.<br />

A type reference directly depends on the referenced type and each of the type arguments, if any.<br />

A union type directly depends on each of the constituent types.<br />

An array type directly depends on its element type.<br />

A tuple type directly depends on each of its element types.<br />

A type query directly depends on the type of the referenced entity.<br />

Given this definition, the complete set of types upon which a type depends is the transitive closure of the<br />

directly depends on relationship. Note that object type literals, function type literals, and constructor type<br />

literals do not depend on types referenced within them and are therefore permitted to circularly reference<br />

themselves through type aliases.<br />

Some examples of type alias declarations:<br />

type StringOrNumber = string | number;<br />

type Text = string | { text: string };<br />

type Coordinates = [number, number];<br />

type NameLookup = Dictionary;<br />

type Callback = (data: string) => void;<br />

type RecFunc = () => RecFunc;<br />

type ObjectStatics = typeof Object;<br />

Interface types have many similarities to type aliases for object type literals, but since interface types offer<br />

more capabilities they are generally preferred to type aliases. For example, the interface type<br />

interface Point {<br />

x: number;<br />

y: number;<br />

}<br />

could be written as the type alias<br />

type Point = {<br />

x: number;<br />

y: number;<br />

};<br />

48

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

Saved successfully!

Ooh no, something went wrong!