What are Ambients in TypeScripts and when to use them?

Technology CommunityCategory: TypeScriptWhat are Ambients in TypeScripts and when to use them?
VietMX Staff asked 1 year ago

Ambients or Ambient declarations are a way of telling the TypeScript compiler that the actual source code exists elsewhere. Ambient declarations help to seamlessly integrate other js libraries into TypeScript.

Ambient declarations are by convention kept in a type declaration file with d.ts extension. The syntax for declaring ambient variables or modules will be as following:

declare module Module_Name {
}

The ambient files should be referenced in the client TypeScript file as shown

/// <reference path = " Sample.d.ts" />