All Guides
Установка TypeScript
Добавьте TypeScript в проект и настройте tsconfig.json.
Beginner10 мин.
Setup Steps
1. Install TypeScript:
npm install -D typescript2. Create tsconfig.json:
npx tsc --init3. Recommended tsconfig.json settings:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}4. Compile:
npx tsc5. Watch mode compilation:
npx tsc --watch6. Run TypeScript with Node.js:
npm install -D tsx
npx tsx src/index.ts7. Type definition files:
npm install -D @types/node @types/express8. package.json scripts:
"scripts": {
"build": "tsc",
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js"
}