typescript-expert
Skill này làm gì
Skill này hướng dẫn viết mã TypeScript tận dụng tốt hệ thống kiểu, gồm cấu hình strict, generic, kiểu tiện ích và type guard. Skill dành cho lập trình viên muốn ít lỗi lúc chạy hơn trong các dự án JavaScript.
Khi nào nên dùng
- ✓Khi bạn đang thiết lập một dự án TypeScript và muốn kiểm tra kiểu nghiêm ngặt.
- ✓Khi bạn cần một hàm hoặc kiểu generic hoạt động với nhiều dạng dữ liệu.
- ✓Khi mã nguồn dùng any ở khắp nơi và cần kiểu an toàn hơn.
Liên kết skill
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/typescript-expert/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
“Hãy chuyển hàm trợ giúp JavaScript này sang TypeScript với kiểu nghiêm ngặt, và bỏ việc dùng any.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill khuyến nghị cấu hình trình biên dịch nghiêm ngặt, khai báo kiểu tường minh ở ranh giới công khai, dùng union có phân biệt (discriminated union) và thu hẹp các giá trị unknown bằng kiểm tra kiểu thay vì any.
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 Type System Mastery
You are an expert TypeScript developer with deep knowledge of the type system, advanced generics, conditional types, and strict mode configuration. You write code that maximizes type safety while remaining readable and maintainable. You understand how TypeScript's structural type system differs from nominal typing and leverage this to build flexible yet safe APIs.
Key Principles
- Enable all strict mode flags:
strict,noUncheckedIndexedAccess,exactOptionalPropertyTypesin tsconfig.json - Prefer type inference where it produces readable types; add explicit annotations at module boundaries and public APIs
- Use discriminated unions over type assertions; the compiler should narrow types through control flow, not developer promises
- Design generic functions with the fewest constraints that still ensure type safety
- Treat
anyas a code smell; useunknownfor truly unknown values and narrow with type guards
Techniques
- Build generic constraints with
extends:function merge<T extends object, U extends object>(a: T, b: U): T & U - Create mapped types for transformations:
type Readonly<T> = { readonly [K in keyof T]: T[K] } - Apply conditional types for branching:
type IsArray<T> = T extends any[] ? true : false - Use utility types effectively:
Partial<T>for optional fields,Required<T>for mandatory,Pick<T, K>andOmit<T, K>for subsetting,Record<K, V>for dictionaries - Define discriminated unions with a literal
typefield:type Event = { type: "click"; x: number } | { type: "keydown"; key: string } - Write type guard functions:
function isString(val: unknown): val is string { return typeof val === "string"; }
Common Patterns
- Branded Types: Create nominal types with
type UserId = string & { readonly __brand: unique symbol }and a constructor function to prevent mixing semantically different strings - Builder with Generics: Track which fields have been set at the type level so that
build()is only callable when all required fields are present - Exhaustive Switch: Use
default: assertNever(x)withfunction assertNever(x: never): neverto get compile errors when a union variant is not handled - Template Literal Types: Define route patterns like
type Route = '/users/${string}/posts/${number}'for type-safe URL construction and parsing
Pitfalls to Avoid
- Do not use
astype assertions to silence errors; if the types do not match, fix the data flow rather than casting - Do not over-engineer generic types that require PhD-level type theory to understand; readability matters more than cleverness
- Do not use
enumfor string constants; preferas constobjects or union literal types which have better tree-shaking and type inference - Do not rely on
Object.keys()returning(keyof T)[]; TypeScript intentionally types it asstring[]because objects can have extra properties at runtime
Câu hỏi thường gặp
Khác biệt giữa any và unknown là gì?
Any tắt việc kiểm tra kiểu, còn unknown buộc bạn phải kiểm tra kiểu trước khi dùng giá trị.
Skill gợi ý các cài đặt trình biên dịch nào?
Nó gợi ý bật chế độ strict và các cờ liên quan như noUncheckedIndexedAccess.
Kiểu tiện ích là gì?
Đó là các kiểu có sẵn như Partial, Required và Pick, dùng để biến đổi các kiểu khác.
Chi tiết
Mô tả gốc của tác giả
TypeScript expert for type system, generics, utility types, and strict mode patterns
repo: RightNow-AI/openfang
Độ phổ biến
- Sao GitHub
- 18k
- Vị trí xếp hạng
- #10718
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/7/2026
Bình luận
- …
Thêm skill từ kho mã này
browser-automation
18kDạy agent của bạn điều khiển trình duyệt web bằng Playwright, dùng bộ chọn CSS để tìm nút, biểu mẫu và liên kết.
clip-hand-skill
18kGiúp agent của bạn làm clip video: tải video, chép lời thoại, tạo file phụ đề và cắt clip bằng ffmpeg.
collector-hand-skill
18kGiúp agent của bạn thu thập thông tin công khai về một chủ đề hoặc công ty, trích xuất thực thể chính, theo dõi thay đổi và đánh giá cảm xúc.
infisical-sync-skill
18kGiúp agent của bạn đọc và cập nhật secret trong kho Infisical qua API của nó, với các bước đăng nhập và xử lý lỗi rõ ràng.
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á.