antfu
Skill này làm gì
Skill này cung cấp cho AI của bạn một bộ thói quen viết code và lựa chọn công cụ cho dự án JavaScript và TypeScript. Skill dành cho lập trình viên muốn các dự án mới được thiết lập gọn gàng và nhất quán.
Khi nào nên dùng
- ✓Khi bạn bắt đầu một dự án TypeScript mới và muốn thiết lập chuẩn, gọn gàng.
- ✓Khi bạn muốn code được chia thành các file rõ ràng và kiểu dữ liệu được tách riêng.
- ✓Khi bạn cần trợ giúp chọn công cụ cho lint, xuất bản hoặc monorepo.
Liên kết skill
https://github.com/antfu/skills/blob/main/skills/antfu/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
“Thiết lập một dự án thư viện TypeScript mới theo các quy ước hiện đại và gọn gàng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent làm theo hướng dẫn đã viết về cách bố trí file, xử lý kiểu dữ liệu, ghi chú runtime và công cụ, và dùng một dự án khởi tạo mẫu làm chuẩn.
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.
Reference template: antfu/starter-ts. When scaffolding a new TypeScript project, mirror its
package.jsonscripts,eslint.config.js,knip.json,tsdown.config.tsand workflows rather than inventing a new layout.
Coding Practices
Code Organization
- Single responsibility: Each source file should have a clear, focused scope/purpose
- Split large files: Break files when they become large or handle too many concerns
- Type separation: Always separate types and interfaces into
types.tsortypes/*.ts - Constants extraction: Move constants to a dedicated
constants.tsfile
Runtime Environment
- Prefer isomorphic code: Write runtime-agnostic code that works in Node, browser, and workers whenever possible
- Clear runtime indicators: When code is environment-specific, add a comment at the top of the file:
// @env node
// @env browser
TypeScript
- Explicit return types: Declare return types explicitly when possible
- Avoid complex inline types: Extract complex types into dedicated
typeorinterfacedeclarations
Explicitness
Favor explicit, traceable code over implicit "magic". A reader (human or agent) should be able to follow where every name comes from without running tooling.
- Explicit imports: Prefer explicit
importstatements. Avoid auto-imports — when a framework provides them (e.g. Nuxt/Nitro), turn them off for new projects (see app-development). - No path aliases by default: Use relative imports (
./foo,../bar). Only use path aliases (@/,~/,#imports, etc.) when they are already configured in the project; don't introduce new ones for greenfield code.
Comments
- Avoid unnecessary comments: Code should be self-explanatory
- Explain "why" not "how": Comments should describe the reasoning or intent, not what the code does
Testing (Vitest)
- Test files:
foo.ts→foo.test.ts(same directory) - Use
describe/itAPI (nottest) - Use
toMatchSnapshotfor complex outputs - Use
toMatchFileSnapshotwith explicit path for language-specific snapshots
Tooling Choices
@antfu/ni Commands
| Command | Description |
|---|---|
ni |
Install dependencies |
ni <pkg> / ni -D <pkg> |
Add dependency / dev dependency |
nr <script> |
Run script |
nu |
Upgrade dependencies |
nun <pkg> |
Uninstall dependency |
nci |
Clean install (pnpm i --frozen-lockfile) |
nlx <pkg> |
Execute package (npx) |
Checking npm Package Versions
Use fast-npm-meta to look up the latest version of a package — it queries a small metadata endpoint instead of downloading the full registry payload (which can be megabytes per package).
nlx fast-npm-meta version vite # 7.3.1
nlx fast-npm-meta version "nuxt@^3.5" # 3.5.22 — range-aware
nlx fast-npm-meta version vite nuxt vue # multiple at once
nlx fast-npm-meta version vite --json # JSON for scripting
nlx fast-npm-meta full vite # full version list + dist-tags
Prefer this over npm view <pkg> version when you only need the latest version, and over reading package.json from the registry directly.
TypeScript Config
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
}
}
ESLint Setup
// eslint.config.js
import antfu from '@antfu/eslint-config'
export default antfu({
type: 'lib', // or 'app' (default)
pnpm: true, // enforce pnpm catalogs in package.json
antislop: true, // flag redundant/duplicated AI-style code, ban explicit `any`
})
Always enable antislop: true. It requires eslint-plugin-slop and eslint-plugin-sonarjs as dev dependencies.
For detailed configuration options: antfu-eslint-config
Knip
Use Knip to catch unused files, exports and dependencies — the linter only sees one file at a time.
// knip.json
{
"$schema": "https://unpkg.com/knip@6/schema.json",
"project": ["src/**/*.ts"],
"ignoreDependencies": []
}
Fix what Knip reports by deleting; only add to ignoreDependencies for tools invoked outside `p
Câu hỏi thường gặp
Skill chỉ dùng cho các dự án của Anthony Fu à?
Không. Đây là các quy ước mà bất kỳ ai cũng có thể áp dụng cho dự án JavaScript và TypeScript.
Skill có dùng được cho code trình duyệt và server không?
Có. Skill ưu tiên code chạy được trên Node, trình duyệt và worker, đồng thời đánh dấu các file chỉ chạy ở một nơi.
Skill có bao quát việc xuất bản thư viện không?
Có. Skill bao quát việc xuất bản thư viện và thiết lập monorepo.
Chi tiết
Mô tả gốc của tác giả
Anthony Fu's opinionated tooling and conventions for JavaScript/TypeScript projects. Use when setting up new projects, configuring ESLint/Prettier alternatives, monorepos, library publishing, or when the user mentions Anthony Fu's preferences.
repo: antfu/skills
Độ phổ biến
- Sao GitHub
- 6.0k
- Vị trí xếp hạng
- #14439
- Giấy phép
- MIT
- Cập nhật
- 30/10/2026
Bình luận
- …
Thêm skill từ kho mã này
antfu-create-pr
6.0kGiúp agent của bạn mở một pull request GitHub rõ ràng từ nhánh của bạn, với bản tóm tắt đơn giản về những gì đã thay đổi và lý do.
antfu-issue-triage
6.0kGiúp agent của bạn rà soát các issue và pull request GitHub đang mở, phát hiện trùng lặp và mục đã sửa, rồi hỏi bạn trước khi hành động.
antfu-query
6.0kCho phép agent của bạn hỏi bạn từng bước về một kế hoạch hoặc ý tưởng cho đến khi hai bên cùng hiểu rõ và đã được kiểm chứng.
antfu-simplify
6.0kGiúp agent của bạn rút gọn các thay đổi code về phiên bản nhỏ nhất nhưng vẫn đúng, bằng cách bỏ những phần không cần thiết.
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á.