For TypeScript 2.x, there are now two steps:
Install a package that defines require
. For example:
npm install @types/node --save-dev
Tell TypeScript to include it globally in tsconfig.json
:
{
"compilerOptions": {
"types": ["node"]
}
}
The second step is only important if you need access to globally available functions such as require
. For most packages, you should just use the import package from 'package'
pattern. There's no need to include every package in the tsconfig.json types array above.