Chuyển đến nội dung
Skillpedia
Lập trình chung75k · #3067

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

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-only-imports/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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.

repo: thedaviddias/Front-End-Checklist

Độ 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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự