Triple-Slash Directives
Triple-slash directives are special comments that provide instructions to the TypeScript compiler. These directives begin with three slashes (///
) and are placed at the top of a file or just before a declaration to control the compilation process.
The most common use of triple-slash directives is to reference external dependencies or declaration files. For example, the /// <reference path="..." />
directive is used to reference external TypeScript declaration files (*.d.ts
) that provide type information for libraries or modules used in the current file.
Triple-slash directives can also be used to configure certain compiler features. For instance, the AMD module directive (/// <amd-module />
) specifies that the current file is an AMD module and allows passing an optional module name to the compiler.
Itβs important to note that starting from TypeScript 3.0, the preferred way to manage dependencies and module resolution is through import statements. Triple-slash directives are mainly used for legacy scenarios or compatibility reasons.