Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.06 KB

variables.md

File metadata and controls

37 lines (28 loc) · 1.06 KB

Variables

For example to tell TypeScript about the process variable you can do:

declare var process: any;

You don't need to do this for process as there is already a community maintained node.d.ts.

This allows you to use the process variable without TypeScript complaining:

process.exit();

We recommend using an interface wherever possible e.g.:

interface Process {
    exit(code?: number): void;
}
declare var process: Process;

This allows other people to extend the nature of these global variables while still telling TypeScript about such modifications. E.g. consider the following case where we add an exitWithLogging function to process for our amusement:

interface Process {
    exitWithLogging(code?: number): void;
}
process.exitWithLogging = function() {
    console.log("exiting");
    process.exit.apply(process, arguments);
};

Let's look at interfaces in a bit more detail next.