typescript-best-practices
Fungsinya
Skill ini memberi aturan untuk menulis kode TypeScript yang andal. Untuk developer yang ingin lebih sedikit error tipe dan lebih sedikit crash tersembunyi.
Kapan dipakai
- ✓Saat Anda meminta agent menulis atau mengedit file TypeScript atau TSX.
- ✓Saat Anda ingin cast tipe yang tidak aman atau tipe yang longgar dihapus dari kode Anda.
- ✓Saat Anda ingin data dari luar diperiksa sebelum kode mengandalkannya.
Link skill
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/typescript-best-practices/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Rapikan tipe di file TypeScript ini agar tidak bergantung pada cast yang tidak aman.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent mengikuti sejumlah aturan, seperti memakai varian berlabel, memakai unknown untuk data dari luar, dan memeriksa data dengan skema sebelum mempercayai tipenya. Aturan ini mencegah keadaan yang mustahil masuk ke dalam kode.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
TypeScript best practices
Apply the type-system-discipline principle skill first.
| Rule | Summary |
|---|---|
| Discriminated unions | Model variants with a kind literal discriminant so impossible states can't be represented. No optional-field bags. |
| Branded types | Brand primitives with & { readonly __brand: "X" } so they can't be mixed up. Validate once at the boundary. A brand comes from a verifying type guard (input is AgentId), never from as. |
| Constructive modeling | Build the shape so the illegal value can't be constructed. [T, ...T[]] for non-empty, [T, T][] for even length, start plus duration for a range. Not a runtime guard, not a wish for refinement types. |
| Simplest total type | Keep T[] while every operation on it stays total. Strengthen to NonEmpty<T> only where the loose type forces !, a cast, or a "should never happen" throw. |
unknown over any |
External data is unknown. |
| Schemas before guards | Before hand-writing a property-by-property type guard, use the repository's runtime schema library and infer the type from the schema, such as z.infer. |
No as casts |
Every as is a runtime crash waiting. Cast only after validation. |
| Narrowing hierarchy | Discriminant switch > in operator > typeof/instanceof > user-defined type guard > as. |
| Type guards | Must verify the claim. A lying guard is worse than as because the bug hides behind a name that says it's safe. Name them isX or hasX. |
| Exhaustiveness | Inline const _exhaustive: never = x; in default arms so the compiler errors when a new variant is added. |
satisfies over as |
Validates the value without widening literal types. |
| Boundary validation | Parse where data crosses in, into a named domain type. Record<string, unknown> (however spelled) stops at that parse. Trust types inside. See the boundary-discipline principle skill. |
| Schema-derived types | Reach for Pick/Omit/Parameters/ReturnType/Awaited/typeof before declaring a new interface. |
| Object args | Pass objects, not positional, so argument order is self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
| Real tests | Don't mock what you can run. Prefer the framework's real test primitives with leak/disposable checks, and verify UI in a running build. Mock only what you can't run locally. |
| Structured telemetry | Prefer structured logger diagnostics with enough context to debug from an id. No console.log in shipped code. |
Examples: references/patterns.md.
Pertanyaan umum
Apakah berlaku untuk file JavaScript biasa?
Aturannya untuk file TypeScript, yaitu .ts dan .tsx.
Apa itu branded type?
Tipe yang menandai sebuah nilai, misalnya ID, agar tidak tertukar dengan nilai lain.
Mengapa menghindari cast dengan as?
Cast memberi tahu compiler untuk mempercayai nilai tanpa memeriksanya, sehingga kode bisa gagal saat dijalankan.
Detail
Deskripsi asli dari pembuat
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
repo: cursor/plugins
Popularitas
- Bintang GitHub
- 15k
- Peringkat
- #11002
- Lisensi
- —
- Diperbarui
- 31/10/2026
Komentar
- …
Skill lain dari repositori ini
advisor
15kMemungkinkan agent Anda berkonsultasi dengan model kedua yang lebih kuat pada titik pemeriksaan penting, seperti sebelum keputusan besar atau saat terhenti pada error, jika Anda mengaktifkannya.
check-agent-compatibility
15kMenjalankan pemeriksaan menyeluruh tentang apakah agent pengodean AI bisa memulai, memverifikasi, dan mendokumentasikan repositori, lalu mengembalikan satu skor kompatibilitas dengan masalah utamanya.
cli-for-agents
15kMengajarkan agent Anda merancang atau meninjau alat baris perintah agar agent AI bisa menjalankannya tanpa prompt, dengan teks bantuan dan contoh yang jelas.
continual-learning
15kMenjaga catatan AGENTS.md Anda tetap mutakhir dengan menyerahkan pekerjaan meninjau chat sebelumnya kepada pembaru memori khusus.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.