TypeScript Cheat Sheet#
Install TypeScript globally#
npm install -g typescript
Initialize TypeScript project#
npx tsc --init
Compile TypeScript file#
tsc app.ts
Run compiled JavaScript#
node app.js
Essential tsconfig.json#
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Topics#
Basic Types Functions Interfaces & Types Classes Generics Utility Types Type Guards Modules