Langsung ke konten
Skillpedia
Pemrograman umum48k Β· #5901

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.md

Salin 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

Gunakan skill ini untuk membantu saya: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/typescript/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

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

  1. Array & Object Operations
  2. Destructuring & Spread
  3. Async / Promises
  4. Functions & Closures
  5. TypeScript Types
  6. React (if applicable)
  7. 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.

repo: sickn33/agentic-awesome-skills

Popularitas

Bintang GitHub
48k
Peringkat
#5901
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa