Tüm Rehberler

TypeScript Kurulumu ve Yapılandırma

TypeScript'i projenize ekleyin ve tsconfig.json yapılandırmasını yapın.

Başlangıç10 dk

Kurulum Adımları

1. TypeScript'i kurun:

npm install -D typescript

2. tsconfig.json oluşturun:

npx tsc --init

3. Önerilen tsconfig.json ayarları:

{
  "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. Derleme:

npx tsc

5. Watch modunda derleme:

npx tsc --watch

6. Node.js ile TypeScript çalıştırma:

npm install -D tsx
npx tsx src/index.ts

7. Type tanım dosyaları:

npm install -D @types/node @types/express

8. package.json script'leri:

"scripts": {
  "build": "tsc",
  "dev": "tsx watch src/index.ts",
  "start": "node dist/index.js"
}