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.

Each module body has a declaration space for local variables (including functions, modules, class<br />

constructor functions, and enum objects), a declaration space for local named types (classes, interfaces,<br />

and enums), and a declaration space for local namespaces (containers of named types). Every declaration<br />

(whether local or exported) in a module contributes to one or more of these declaration spaces.<br />

10.3 Import Declarations<br />

Import declarations are used to create local aliases for entities in other modules.<br />

ImportDeclaration:<br />

import Identifier = EntityName ;<br />

EntityName:<br />

ModuleName<br />

ModuleName . Identifier<br />

An EntityName consisting of a single identifier is resolved as a ModuleName and is thus required to<br />

reference an internal module. The resulting local alias references the given internal module and is itself<br />

classified as an internal module.<br />

An EntityName consisting of more than one identifier is resolved as a ModuleName followed by an<br />

identifier that names one or more exported entities in the given module. The resulting local alias has all<br />

the meanings and classifications of the referenced entity or entities. (As many as three distinct meanings<br />

are possible for an entity name—namespace, type, and member.) In effect, it is as if the imported entity or<br />

entities were declared locally with the local alias name.<br />

In the example<br />

module A {<br />

export interface X { s: string }<br />

export var X: X;<br />

}<br />

module B {<br />

interface A { n: number }<br />

import Y = A; // Alias only for module A<br />

import Z = A.X; // Alias for both type and member A.X<br />

var v: Z = Z;<br />

}<br />

within 'B', 'Y' is an alias only for module 'A' and not the local interface 'A', whereas 'Z' is an alias for all<br />

exported meanings of 'A.X', thus denoting both an interface type and a variable.<br />

If the ModuleName portion of an EntityName references an instantiated module, the ModuleName is<br />

required to reference the module instance when evaluated as an expression. In the example<br />

137

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

Saved successfully!

Ooh no, something went wrong!