Recommended:
- node.js 8.11.3 LTS + npm installed
- An IDE with TypeScript support, e.g. Jetbrains WebStorm
In order to have a minimal development environment for using TypeScript, execute the following commands on the command line:
- To create node project and package.json
npm init
- Install dependencies
npm install typescript --save
# short form
npm i typescript -S
- Edit package.json and add tsc and start script
{
"name": "typescript-basics",
"version": "1.0.0",
"description": "",
"private": true,
"main": "index.js",
"scripts": {
"tsc": "tsc",
"start": "npm run tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"typescript": "^2.9.2"
}
}
- Initialize TypeScript project
npm run tsc -- --init
- Create source folder and index.ts file with "Hello World" output (works on UNIX command line)
mkdir src
touch src/index.ts
echo "console.log('Hello World!');" > src/index.ts
- Build it
npm run start
- Run it
node src/index.js