TypeScript
Allows you to catch errors earlier.
Tutorials:
- https://www.youtube.com/watch?v=d56mG7DezGs (Programming with Mosh)
General Knowledge
Build-in types JS types TS types
Custom types
Initial project set-up
Initialize a new Node.js project:
npm init -yInstall TypeScript:
# globally
npm i -g typescript
# locally
npm install typescript --save-dev
# verify install
tsc -vGenerate a TypeScript configuration file
tsc --initSettings:
- target: "ES2016", "ES2018"
- rootDir: "./", "./src"
- outdit: "./dist"
- removeComments: true
- NoEmitOnError: true
With config file, running tsc with no
arguments will compile the whole project.
Compile TypeScript to JavaScript
Create a .ts file and add the code, for
example:
console.log('Hello world!');In terminal run:
tsc index.tsThis will generate a .js file.
Debugging TypeScript
Debug using VS Code.