TypeScript Essentials
TypeScript Project Setup
TypeScript Project Setup
Section titled “TypeScript Project Setup”Learn to set up a TypeScript project from scratch.
Initialize Project
Section titled “Initialize Project”# Create directorymkdir my-ts-project && cd my-ts-project
# Initialize npmnpm init -y
# Install TypeScriptnpm install typescript --save-dev
# Create tsconfig.jsonnpx tsc --inittsconfig.json
Section titled “tsconfig.json”{ "compilerOptions": { "target": "ES2020", "module": "ESNext", "lib": ["ES2020", "DOM"], "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "declaration": true, "declarationMap": true, "sourceMap": true }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"]}Project Structure
Section titled “Project Structure”my-ts-project/├── src/│ ├── index.ts│ └── utils/│ └── helpers.ts├── dist/├── package.json└── tsconfig.jsonBuild Scripts
Section titled “Build Scripts”{ "scripts": { "build": "tsc", "watch": "tsc --watch", "start": "node dist/index.js", "dev": "ts-node src/index.ts" }}Development Tools
Section titled “Development Tools”# ts-node for running TypeScript directlynpm install ts-node --save-dev
# nodemon for auto-restartnpm install nodemon --save-dev
# ESLint for lintingnpm install eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin --save-dev