type-only-imports
Skill này làm gì
Skill này kiểm tra các câu lệnh import TypeScript và đánh dấu đúng những import chỉ dành cho kiểu. Skill dành cho lập trình viên muốn bundle nhỏ hơn và ít lỗi phụ thuộc hơn.
Khi nào nên dùng
- ✓Khi một file TypeScript import các module chỉ dùng làm kiểu.
- ✓Khi một bundle chứa các module có vẻ chỉ được kéo vào để làm kiểu.
- ✓Khi thiết lập một dự án TypeScript mới với quy tắc import gọn gàng.
Liên kết skill
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-only-imports/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
“Bản build TypeScript của tôi kéo vào một module lớn mà tôi chỉ dùng làm kiểu. Bạn có thể sửa các import không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tìm các import chỉ dùng làm kiểu và đổi chúng thành import type. Sau đó trình biên dịch loại bỏ chúng khi mã được build.
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.
Use import type for type-only imports
Regular imports cause the JavaScript runtime to evaluate and execute the imported module even when only a TypeScript type from that module is used. This can increase bundle size, introduce unintended side effects, and create circular dependency issues that are otherwise avoidable. Using import type makes the erased-at-runtime nature of type imports explicit and enables bundlers and the TypeScript compiler to handle them optimally.
Quick Reference
- import type is erased entirely at compile time — no runtime module evaluation
- Prevents accidentally importing a value when only a type is needed
- Reduces circular dependency issues caused by type-only relationships
- verbatimModuleSyntax in TypeScript 5 enforces this automatically
Check
Review the import statements in this TypeScript file and identify any imports where only types or interfaces are used. These should use import type instead of a regular import.
Fix
Convert the identified regular imports to import type where the imported binding is only used as a TypeScript type annotation and not as a runtime value.
Explain
Explain the difference between import and import type in TypeScript, why type-only imports should be declared explicitly, and how verbatimModuleSyntax enforces this at the compiler level.
Code Review
Inspect all import statements in this file. For each import, check whether the imported name appears only in type positions (annotations, generics, implements clauses) versus runtime positions (function calls, new, typeof). Flag any regular import that is used only as a type.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/type-only-imports
Câu hỏi thường gặp
import type làm gì?
Nó cho trình biên dịch biết import này bị xóa lúc build, nên không có module nào được tải khi chạy.
verbatimModuleSyntax là gì?
Đó là một cài đặt của TypeScript 5 để áp dụng quy tắc này tự động, theo skill.
Việc này có giúp giảm phụ thuộc vòng tròn không?
Skill nói rằng các phụ thuộc vòng tròn có thể tránh được thì có thể giảm bằng cách dùng import chỉ dành cho kiểu.
Chi tiết
Mô tả gốc của tác giả
Use when auditing import statements in TypeScript files, setting up a new TypeScript project, or investigating unexpected bundle inclusions from type-only dependencies.
Độ phổ biến
- Sao GitHub
- 75k
- Vị trí xếp hạng
- #3067
- Giấy phép
- MIT
- Cập nhật
- 31/10/2026
Bình luận
- …
Thêm skill từ kho mã này
frontendchecklist
75kKiểm tra mã frontend và trang trực tiếp theo hơn 380 quy tắc về khả năng tiếp cận, tốc độ, SEO và bảo mật, bằng một công cụ dòng lệnh.
frontend-checklist-global
75kKiểm toán một dự án frontend theo đủ 386 quy tắc của Front-End Checklist, và đưa cách sửa cụ thể cho từng vấn đề tìm thấy.
404-page
75kKiểm tra xem trang báo thiếu của bạn có đưa ra các liên kết hữu ích và trả về mã trạng thái 404 thật hay không, để giúp khách bị lạc tìm đường.
about-page
75kKiểm tra xem trang web có trang Giới thiệu rõ ràng giải thích ai điều hành nó hay không, để xây dựng niềm tin với khách và công cụ tìm kiếm.
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á.