TypeScript

12         

Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist “ambiently” and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag.

   

12.1    

         

AmbientDeclaration:
declare   AmbientVariableDeclaration
declare   AmbientFunctionDeclaration
declare   AmbientClassDeclaration
declare   AmbientEnumDeclaration
declare   AmbientModuleDeclaration
declare   

         

12.1.1     

   

AmbientVariableDeclaration:
var   Identifier    TypeAnnotationopt   ;

   

   

12.1.2     

   

AmbientFunctionDeclaration:
function   ;

         

   

12.1.3     

   

AmbientClassDeclaration:
class   Identifier   TypeParametersopt   ClassHeritage   {   }

AmbientClassBody:
AmbientClassBodyElementsopt

AmbientClassBodyElements:
AmbientClassBodyElement
AmbientClassBodyElements   AmbientClassBodyElement

AmbientClassBodyElement:
AmbientConstructorDeclaration
AmbientMemberDeclaration
IndexSignature

AmbientConstructorDeclaration:
constructor   (   ParameterListopt   )   ;

AmbientMemberDeclaration:
PublicOrPrivateopt   
staticopt   PropertyName   TypeAnnotationopt   ;
PublicOrPrivateopt   
staticopt   PropertyName   CallSignature   ;

12.1.4  Ambient Enum Declarations

An ambient enum declaration declares an enum type and an enum object in the containing module.

AmbientEnumDeclaration:
enum   Identifier   {   AmbientEnumBodyopt   }

AmbientEnumBody:
AmbientEnumMemberList   
,opt

AmbientEnumMemberList:
AmbientEnumMember
AmbientEnumMemberList   
,   AmbientEnumMember

AmbientEnumMember:
PropertyName
PropertyName   =   IntegerLiteral

An AmbientEnumMember that includes an IntegerLiteral value is considered a constant member. An AmbientEnumMember with no IntegerLiteral value is considered a computed member.

12.1.5  Ambient Module Declarations

An ambient module declaration declares an internal module.

AmbientModuleDeclaration:
module   IdentifierPath   {   AmbientModuleBody   }

AmbientModuleBody:
AmbientModuleElementsopt

AmbientModuleElements:
AmbientModuleElement
AmbientModuleElements   AmbientModuleElement

AmbientModuleElement:
exportopt   AmbientVariableDeclaration
exportopt   AmbientFunctionDeclaration
exportopt   AmbientClassDeclaration
exportopt   InterfaceDeclaration
exportopt   AmbientEnumDeclaration
exportopt   AmbientModuleDeclaration
exportopt   ImportDeclaration

Except for ImportDeclarations, AmbientModuleElements always declare exported entities regardless of whether they include the optional export modifier.

12.1.6  Ambient External Module Declarations

An AmbientExternalModuleDeclaration declares an external module. This type of declaration is permitted only in the global module. The StringLiteral must specify a top-level external module name. Relative external module names are not permitted.

AmbientExternalModuleDeclaration:
module   StringLiteral   {    AmbientExternalModuleBody   }

AmbientExternalModuleBody:
AmbientExternalModuleElementsopt

AmbientExternalModuleElements:
AmbientExternalModuleElement
AmbientExternalModuleElements   AmbientExternalModuleElement

AmbientExternalModuleElement:
AmbientModuleElement
ExportAssignment
exportopt   ExternalImportDeclaration

An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules only through top-level external module names. Relative external module names are not permitted.

If an ambient external module declaration includes an export assignment, it is an error for any of the declarations with the module to specify an export modifier. If an ambient external module declaration contains no export assignment, entities declared in the module are exported regardless of whether their declarations include the optional export modifier.

 


TypeScript Language Specification (converted to HTML pages by @Bartvds)

Version 0.9.1

August 2013

Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement  Version 1.0 ('OWF 1.0') as of October 1, 2012. The OWF 1.0 is available at  http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.

TypeScript is a trademark of Microsoft Corporation.