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.

12 Ambients<br />

Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations<br />

differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new<br />

variables, functions, classes, enums, or modules, ambient declarations provide type information for<br />

entities that exist "ambiently" and are included in a program by external means, for example by<br />

referencing a JavaScript library in a tag.<br />

12.1 Ambient Declarations<br />

Ambient declarations are written using the declare keyword and can declare variables, functions, classes,<br />

enums, internal modules, or external modules.<br />

AmbientDeclaration:<br />

declare AmbientVariableDeclaration<br />

declare AmbientFunctionDeclaration<br />

declare AmbientClassDeclaration<br />

declare AmbientEnumDeclaration<br />

declare AmbientModuleDeclaration<br />

12.1.1 Ambient Variable Declarations<br />

An ambient variable declaration introduces a variable in the containing declaration space.<br />

AmbientVariableDeclaration:<br />

var Identifier TypeAnnotation opt ;<br />

An ambient variable declaration may optionally include a type annotation. If no type annotation is<br />

present, the variable is assumed to have type Any.<br />

An ambient variable declaration does not permit an initializer expression to be present.<br />

12.1.2 Ambient Function Declarations<br />

An ambient function declaration introduces a function in the containing declaration space.<br />

AmbientFunctionDeclaration:<br />

function Identifier CallSignature ;<br />

Ambient functions may be overloaded by specifying multiple ambient function declarations with the same<br />

name, but it is an error to declare multiple overloads that are considered identical (section 3.10.2) or differ<br />

only in their return types.<br />

Ambient function declarations cannot specify a function bodies and do not permit default parameter<br />

values.<br />

151

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

Saved successfully!

Ooh no, something went wrong!