-
Install TypeScript with npm:
npm install -g typescript
-
Create a tsconfig.json file which contains the TypeScript settings for the project. Could be done by running
tsc --init
in the terminal in the project folder. -
Compile (transpile) the ts-files into js-files. Could be done by
tsc filename.ts
in terminal. -
Execute Run Build Task (Ctrl+Shift+B) in VS Code to compile all.
-
Run the code by node
filename.js
in terminal or by pressing F5 in VS Code which launches a program by the it's launch.json settings. -
Create the package.json with
npm init
See also: https://code.visualstudio.com/docs/typescript/typescript-compiling
Type tsc
to build all files in the root folder
https://code.visualstudio.com/docs/typescript/typescript-tutorial
For debugging in VS Code: create a launch.json (in .vscode-Folder) within the VS Code debug view Example for launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\out\\HelloApp.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"preLaunchTask": "tsc: build - tsconfig.json",
}
]
}
see https://medium.com/@RupaniChirag/writing-unit-tests-in-typescript-d4719b8a0a40
- NPM Install Command for Mocha/Chai
npm i -D chai mocha nyc ts-node typescript
npm i -D @types/chai @types/mocha
- Add/edit test script configuration in package.json
"scripts": {
"test": "mocha -r ts-node/register tests/**/*.test.ts",
"coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" npm run test"
}
- Add new section in launch.json
{
"type": "node",
"request": "launch",
"name": "Mocha Current File",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--no-timeouts",
"--colors",
"${file}",
"--require",
"ts-node/register"
],
"console": "integratedTerminal",
"sourceMaps": true,
"internalConsoleOptions": "neverOpen"
}
Run test with Debug Launcher of VS Code or npm test
in terminal