Typescript Project Initialization
Create tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"watch": true,
"allowJs": true,
"removeComments": true
}
}
Node modules won’t be found by Typscript until you install the type descriptions:
npm install --save-dev @types/node
And also you should do this to other javascript modules.
In case you want a stack trace in typescript
Install source map support … and let it do the work for you
npm install --save-dev source-map-support
To use it:
require('source-map-support').install()
In your entry files, I usually put this at the top of my test files. In production code, I don’t want an extra require
.
By the way, it’s a good idea to code Typescript using Visual Studio Code because of its great support.
Here are some addition steps if you’re using it
- Add build task using the
tsconfig.json
- Build (typically
ctrl + shift + b
) - Code