type-only-imports
它能做什么
这项技能检查 TypeScript 的导入语句,并正确标记只用于类型的导入。适用于希望打包体积更小、依赖问题更少的开发者。
适用场景
- ✓当 TypeScript 文件导入的模块只用作类型的时候。
- ✓当打包结果中包含似乎只为类型而引入的模块的时候。
- ✓当你在搭建新的 TypeScript 项目,并希望有清晰的导入规则的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-only-imports/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 TypeScript 构建引入了一个很大的模块,但我只把它用作类型。请帮我修复这些导入。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出只用作类型的导入,并把它们改为 import type。之后编译器会在构建代码时将其移除。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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
常见问题
import type 有什么作用?
它告诉编译器,该导入会在构建时被删除,因此不会加载任何运行时模块。
verbatimModuleSyntax 是什么?
根据这项技能,它是 TypeScript 5 的一项设置,会自动强制执行这一规则。
这能帮助解决循环依赖吗?
这项技能指出,使用只用于类型的导入,可以减少可以避免的循环依赖。
详情
作者的原始描述
Use when auditing import statements in TypeScript files, setting up a new TypeScript project, or investigating unexpected bundle inclusions from type-only dependencies.
热度
- GitHub 星标
- 75k
- 排名
- #3067
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。