Basic Types, Enums, Types, Interfaces, Classes, Functions, Generics
npm init
npm install typescript
# global install
npm install -g typescript
# target a specific file
npx tsc index.ts
# compile all files in the directory with .ts
npx tsc
npx tsc --watch index
- compiler runs live while you are coding so changes reflect in the js code
- you also get to see live compile time errors everytime you save
npx tsc --init
"target": "es6"
- telling what version of JS to transpile to.
"rootDir": "./src",
and"outDir": "./dist"
- production code (transpiled js) goes into โ
outDir
- source code will be the โ
rootDir
- production code (transpiled js) goes into โ
- Browsers still cannot see index.ts files
- still need to bring
.js
version in html files for instance for script tags<script src="index.js"></script>
- still need to bring
npx create-react-app my-app --template typescript