TSX (TypeScript XML — React)
TSX menggabungkan pengetikan statis TypeScript dengan sintaks JSX untuk komponen React. Ini adalah ekstensi file standar untuk komponen React bertipe, menyediakan pemeriksaan tipe waktu kompilasi untuk props, state, dan event handler.
Tipe MIME
text/tsx
Tipe
Teks
Kompresi
Lossless
Kelebihan
- + Type-safe React components with prop validation at compile time
- + Excellent IDE autocomplete for props and event handlers
- + Catches common React bugs before runtime
Kekurangan
- − Requires TypeScript compiler configuration
- − Generic component syntax can conflict with JSX angle brackets
- − More boilerplate than plain JSX for simple components
Kapan Menggunakan .TSX
Gunakan TSX untuk semua komponen React dalam proyek TypeScript — menyediakan keamanan tipe untuk props, state, context, dan hooks.
Detail Teknis
File TSX diproses oleh compiler TypeScript, yang memeriksa tipe kode dan mengubah JSX menjadi JavaScript. Komponen generik menggunakan tanda kurung sudut yang dibedakan compiler dari elemen JSX.
Riwayat
TSX muncul secara alami dari kombinasi TypeScript dan JSX seiring React dan TypeScript mendapatkan popularitas bersama. Pada tahun 2020, TSX menjadi default untuk proyek React baru yang menggunakan TypeScript.