typescript
Fungsinya
Panduan ini mengajarkan cara menulis kode TypeScript/JavaScript yang lebih efisien dan jelas. Panduan ini memberikan contoh kebiasaan yang bisa membuat kode lebih rumit atau lambat, lalu menyarankan alternatif yang lebih sederhana dan lebih cepat.
Kapan dipakai
- βSaat menulis kode TypeScript atau JavaScript.
- βSaat Anda ingin membuat kode lebih mudah dibaca.
- βUntuk mengoptimalkan performa kode Anda.
Link skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/typescript/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
βBagaimana cara menulis ulang loop ini agar lebih efisien di JavaScript?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Panduan ini membandingkan 'cara lama' (kurang efisien) dengan 'cara baru' (lebih efisien) menggunakan contoh kode. Panduan ini membahas operasi array dan object, fungsi, serta penggunaan tipe di TypeScript.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
TypeScript / JavaScript: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for typescript.
Table of Contents
- Array & Object Operations
- Destructuring & Spread
- Async / Promises
- Functions & Closures
- TypeScript Types
- React (if applicable)
- Anti-patterns specific to TS/JS
1. Array & Object Operations {#arrays}
// β Imperative push loop
const result: string[] = []
for (const item of items) {
if (item.active) result.push(item.name.toUpperCase())
}
// β
const result = items.filter(i => i.active).map(i => i.name.toUpperCase())
// β Manual reduce for sum
let total = 0
for (const o of orders) total += o.amount
// β
const total = orders.reduce((sum, o) => sum + o.amount, 0)
// β Manual object copy + override
const updated = Object.assign({}, user)
updated.name = "Alice"
// β
const updated = { ...user, name: "Alice" }
// β Existence check before property access
const city = user.address ? user.address.city : undefined
// β
const city = user.address?.city
2. Destructuring & Spread {#destructuring}
// β Separate variable assignments
const name = user.name
const age = user.age
// β
const { name, age } = user
// β Index access for array elements
const first = arr[0]
const second = arr[1]
// β
const [first, second] = arr
// β Merging arrays with concat
const merged = a.concat(b).concat(c)
// β
const merged = [...a, ...b, ...c]
// β Omitting a key by delete (mutates)
const copy = { ...obj }
delete copy.password
// β
β destructure to omit
const { password, ...safe } = obj
3. Async / Promises {#async}
// β Promise chain when async/await is cleaner
fetchUser(id)
.then(user => fetchOrders(user.id))
.then(orders => process(orders))
.catch(handleError)
// β
try {
const user = await fetchUser(id)
const orders = await fetchOrders(user.id)
process(orders)
} catch (e) {
handleError(e)
}
// β Sequential awaits for independent operations
const user = await fetchUser(id)
const config = await fetchConfig()
// β
β run in parallel
const [user, config] = await Promise.all([fetchUser(id), fetchConfig()])
// β Wrapping already-async function in new Promise
const result = await new Promise((resolve) => {
someAsyncFn().then(resolve)
})
// β
const result = await someAsyncFn()
Don't await inside a .map() without Promise.all β it sequences what should be parallel.
4. Functions & Closures {#functions}
// β Arrow function with unnecessary block body
const double = (x: number) => { return x * 2 }
// β
const double = (x: number) => x * 2
// β Default parameter with if-guard
function greet(name?: string) {
if (!name) name = "World"
return `Hello, ${name}`
}
// β
function greet(name = "World") {
return `Hello, ${name}`
}
// β IIFE for no reason in module scope
;(function() {
const x = compute()
doSomething(x)
})()
// β
β just top-level statements in a module
const x = compute()
doSomething(x)
5. TypeScript Types {#types}
// β Explicit return type when inference is obvious
function add(a: number, b: number): number {
return a + b
}
// β
β let TS infer simple return types
function add(a: number, b: number) {
return a + b
}
// β any
function process(data: any) { ... }
// β
β use unknown + type guard, or a proper type/generic
function process<T extends Record<string, unknown>>(data: T) { ... }
// β Redundant interface for single-use inline shape
interface UserNameProps { name: string }
function UserName({ name }: UserNameProps) { ... }
// β
β inline for single-use
function UserName({ name }: { name: string }) { ... }
// Extract interface when reused in 2+ places
// β Type assertion (as) to silence a real type error
const el = document.getElementById("app") as HTMLDivElement
el.innerText = "hi" // crashes if el is null
// β
const el = document.getElementById("app")
if (!(el instanceof HTMLDivElement)) throw new Error("Missing #app")
el.innerText = "hi"
Prefer type for unions/intersections/aliases; interface for extensible object shapes.
6. React (if applicable) {#react}
// β Effect for derived state
β¦
Pertanyaan umum
Apa itu 'Destructuring & Spread'?
Ini adalah cara untuk mengambil nilai dari array atau object ke dalam variabel terpisah (destructuring), atau menyebarkan elemen array atau properti object ke tempat lain, sehingga kode menjadi lebih ringkas.
Mengapa menggunakan `async/await` daripada `.then()`?
`async/await` membuat kode asinkron (yang menangani operasi yang memakan waktu) terlihat lebih mirip kode sinkron (dijalankan baris demi baris), sehingga lebih mudah dibaca dan error-nya lebih mudah dikelola.
Apa itu 'Type Assertion'?
Ini adalah ketika Anda memberi tahu TypeScript bahwa Anda yakin sebuah nilai bertipe tertentu, meskipun TypeScript tidak bisa memastikannya. Sebaiknya hindari cara ini dan biarkan TypeScript menyimpulkan tipe, atau gunakan pengecekan tipe.
Detail
Deskripsi asli dari pembuat
Language-specific super-code guidelines for typescript.
Popularitas
- Bintang GitHub
- 48k
- Peringkat
- #5901
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- β¦
Skill lain dari repositori ini
00-andruia-consultant
48kMembantu agent Anda memulai atau meningkatkan proyek AI. Agent menganalisis kode, menyarankan tools, dan membuat rencana aksi dalam bahasa Spanyol.
007
48kMemungkinkan agent Anda melakukan audit keamanan dan threat modeling. Berguna untuk melindungi proyek dari serangan dan celah keamanan.
10-andruia-skill-smith
48kMembantu agent Anda membuat atau meningkatkan tools AI. Agent mendefinisikan cara kerja tools, menulis dokumentasi, dan memvalidasi strukturnya.
20-andruia-niche-intelligence
48kMemungkinkan agent Anda membuat ringkasan industri tertentu. Berguna untuk memahami konteks, aturan, pola penggunaan, dan risiko proyek dengan sumber terpercaya.
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.