TypeScript
TypeScript adalah superset JavaScript yang diketik secara statis, dikembangkan oleh Microsoft. File TS berisi anotasi tipe, interface, dan generik yang menangkap kesalahan pada waktu kompilasi sebelum kode dijalankan. TypeScript dikompilasi ke JavaScript biasa untuk eksekusi browser dan Node.js.
Tipe MIME
text/typescript
Tipe
Teks
Kompresi
Lossless
Kelebihan
- + Catches type errors at compile time before runtime
- + Excellent IDE support with autocomplete and refactoring
- + Gradual adoption — any JavaScript is valid TypeScript
- + Industry standard for large-scale web applications
Kekurangan
- − Requires a compilation step (tsc or bundler)
- − Type complexity can become overwhelming (conditional types, mapped types)
- − Learning curve for developers new to static typing
Kapan Menggunakan .TS
Gunakan TypeScript untuk proyek JavaScript apa pun yang mendapat manfaat dari keamanan tipe — codebase besar, proyek tim, perpustakaan, dan API.
Detail Teknis
TypeScript menambahkan tipe statis, interface, enum, generik, dan dekorator di atas JavaScript. Compiler TypeScript (tsc) menghapus tipe dan menghasilkan JavaScript standar. File .d.ts menyediakan deklarasi tipe untuk perpustakaan.
Riwayat
Microsoft merilis TypeScript pada tahun 2012, dipimpin oleh Anders Hejlsberg (pencipta C# dan Turbo Pascal). TypeScript telah menjadi standar untuk aplikasi JavaScript berskala besar, digunakan oleh Angular, Next.js, dan sebagian besar proyek besar.