November 2019
Beginner
804 pages
20h 1m
English
Ambient modules are modules defined as part of type definitions in order to provide information to TypeScript.
The declare module "name" syntax is used to define the name of the module that can be imported for those libraries (for example, localForage, which we used in Chapter 4, Leveraging Generics and Enums to Build a Media Management Web Application).
Here's a simple example:
// my-module-with-reexports.ts
export {log, Message, MessageType} from "./my-utils-module";
As a second example, here's how the localForage module is declared by its typings:
declare module "localforage" {
let localforage: LocalForage;
export = localforage;
}
When TypeScript finds those type declarations, it knows that you can import that module ...
Read now
Unlock full access