TypeScript, JavaScript'in static type'lı süper kümesi. 2026'da yeni projelerin %85'i TypeScript ile başlıyor. Runtime hatalarını compile-time'da yakalar, IDE intellisense'i 10x güçlendirir.
Neden TypeScript?
- Runtime hatalar compile-time'da yakalanır ("undefined.foo" hatasız)
- Refactoring güvenli — değişiklik etki alanı belli
- IDE autocomplete + intellisense 10x güçlü
- Self-documenting code — type'lar bir nevi doc
- Team onboarding hızlı — yeni dev kodu daha hızlı anlar
- API contract'ları net
Temel kavramlar
- Primitive types
- string, number, boolean, null, undefined
- Array
- string[] veya Array<string>
- Object
- { name: string; age: number }
- Function
- (x: number, y: number) => number
- Union
- string | number
- Intersection
- TypeA & TypeB
- Generic
- Array<T>, Promise<User>
Type vs Interface
`type` daha esnek (union, intersection, primitives). `interface` extension için iyi (declaration merging). Pratikte object shape'ler için interface, type alias için type kullan. Karışıklık yapmayın — proje genelinde tek konvansiyon belirle.
Strict mode önemli
tsconfig.json'da "strict": true → strictNullChecks, noImplicitAny vs hepsi aktif. Gerçek tip güvenliği için şart. Yeni proje strict mode ile başlat, mevcut projeyi kademeli geçir.
Migration stratejisi (JS → TS)
- 01tsc init ile tsconfig.json oluştur — strict: false başlangıçta
- 02.js dosyalarını .ts'e rename — tek tek
- 03JSDoc comments varsa tip otomatik çıkarılır
- 04@ts-expect-error veya // @ts-ignore ile geçici bypass
- 05any tip'lerini kademeli olarak gerçek tip'le değiştir
- 06Tüm dosya TS olunca strict mode aç
Yararlı patterns
- Type narrowing: typeof, instanceof, in
- Discriminated unions: { type: 'success'; data: ... } | { type: 'error'; message: ... }
- Utility types: Partial, Required, Pick, Omit, Record
- satisfies operator (TS 4.9+) — type inference koruyarak doğrula
- Template literal types: `${string}-${string}`
Modern toolchain
- tsc — official TypeScript compiler
- esbuild — TS'i çok hızlı transpile (build)
- swc — Rust ile yazılmış alternative
- Vite — esbuild + Rollup combo, default seçim
- tsx — Node.js'de TS dosyalarını direkt çalıştır
- Bun — TS native runtime
Şunu yapmayın: 'any' tip her yerde kullanmak
any kullanmak "TypeScript yazmıyorsunuz" demek. unknown tip kullanın — narrow etmek zorunda kalırsınız, type safety korunur.
NotJS projenizi TS'e migrate edelim: +90 537 729 40 97 (WhatsApp). Mevcut codebase analiz + 6-8 hafta tam migration.