typescript
Skill này làm gì
Hướng dẫn này dạy cách viết code TypeScript/JavaScript hiệu quả và rõ ràng hơn. Nó đưa ví dụ về các cách làm phức tạp hoặc chậm, và gợi ý các cách đơn giản, nhanh hơn để thay thế.
Khi nào nên dùng
- ✓Khi viết code TypeScript hoặc JavaScript.
- ✓Khi bạn muốn code dễ đọc hơn.
- ✓Khi muốn tối ưu hiệu năng code.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/typescript/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm sao để viết lại vòng lặp này hiệu quả hơn trong JavaScript?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Hướng dẫn so sánh cách làm “cũ” (kém hiệu quả) với cách làm “mới” (hiệu quả hơn) bằng ví dụ code. Nội dung bao gồm thao tác với mảng và đối tượng, hàm và việc dùng kiểu trong TypeScript.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
…
Câu hỏi thường gặp
“Destructuring & Spread” là gì?
Đây là cách lấy giá trị từ mảng hoặc đối tượng vào các biến riêng (destructuring), hoặc “trải” các phần tử của mảng hay thuộc tính của đối tượng vào chỗ khác, giúp code gọn hơn.
Vì sao dùng `async/await` thay vì `.then()`?
`async/await` làm code bất đồng bộ (xử lý các tác vụ tốn thời gian) trông giống code đồng bộ (chạy từng dòng), giúp dễ đọc và quản lý lỗi hơn.
“Type Assertion” là gì?
Đó là khi bạn nói với TypeScript rằng bạn chắc chắn một giá trị thuộc kiểu nhất định, dù nó không tự chứng minh được. Nói chung nên tránh và để TypeScript tự suy luận kiểu hoặc dùng kiểm tra kiểu.
Chi tiết
Mô tả gốc của tác giả
Language-specific super-code guidelines for typescript.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #5901
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.