Set TS version for VSCode intellisence
VS Code command palette: > TypeScript: Select TypeScript version
Format TypeScript Document
This will format the entire document.
Shift + Alt + F
Shift + Option + F
Format Selection
Ctrl + K Ctrl + F
Cmd + K Cmd + F
Duplicate code line
Alt + Shift + Down Arrow
or Alt + Shift + Up Arrow
Check TypeScript versions: npm list typescript
1. Install Node.js
2. Install TypeScript
npm install -g typescript
3. Initialize Your Project
npm init -y
4. Create a TypeScript Configuration File
tsc --init
This file enables you to specify various compiler options such as the target JavaScript version, the module system, source maps, the output directory, etc.
5. Create a .ts file in your project
For example,
hello.ts
.6. Compile TypeScript
tsc hello.ts
7. Automate the Compilation Process
To make the process easier, you can configure VS Code to build your TypeScript files automatically:
Ctrl + Shift + P
.Tasks: Configure Default Build Task
and press Enter.tsc: build - tsconfig.json
from the list. This creates atasks.json
file in the.vscode
folder.Now, you can build your TypeScript project by pressing
Ctrl + Shift + B
or running the build task through the Terminal menu.8. Watch Mode
To automatically compile your TypeScript files whenever you save them, you can start the TypeScript compiler in watch mode. In the terminal, run:
tsc --watch
This command will monitor your TypeScript files for changes and recompile them automatically.