no-explicit-any
它能做什么
这个技能检查 TypeScript 文件中的 “any” 类型,它会关闭类型检查。它面向希望 TypeScript 能及早发现更多错误的开发者。
适用场景
- ✓你请智能体检查 TypeScript 文件的类型安全问题的时候。
- ✓代码检查器对 “any” 类型发出警告,而你想正确修复的时候。
- ✓函数处理来自应用外部的数据,并希望在使用前检查的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/no-explicit-any/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我检查 TypeScript 文件,并把 “any” 类型换成更安全的类型吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出所有使用 “any” 的地方,包括隐式和断言的情况。它会建议用 “unknown”、泛型或校验来替换,并说明每个值在使用处需要做的检查。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Avoid the any type — use unknown, generics, or type guards instead
The any type is a local opt-out that becomes a global problem: a function returning any propagates unchecked types to every caller, silently undermining the type system across the entire codebase. Replacing any with unknown forces type narrowing at the point of use, turning latent runtime errors into compile-time failures where they are cheapest to fix.
Quick Reference
- any disables all type checking for a value and cascades to callers
- unknown is the safe alternative — it requires a type check before use
- Use generics to express "I accept any type, but it stays consistent"
- At API boundaries, validate with Zod rather than asserting with as Type
Check
Scan this TypeScript file for uses of the any type (explicit annotations, implicit any from missing types, and type assertions to any). Report each location and suggest a safer alternative.
Fix
Replace the any types in this code with unknown (for values of unknown shape), appropriate generics (for type-consistent operations), or Zod validation (for external data). Show the narrowing or generic constraint needed at each usage site.
Explain
Explain why the any type undermines TypeScript's guarantees, how unknown differs from any, and when a type assertion (as Type) is acceptable versus dangerous.
Code Review
Review all type annotations, function signatures, and external data handling in this file. Flag every explicit or implicit any, any type assertion that lacks a preceding type guard, and any return types inferred as any from untyped dependencies.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/no-explicit-any
常见问题
“any” 和 “unknown” 有什么区别?
“any” 会完全关闭检查,而 “unknown” 要求在使用该值前先进行类型检查。
使用类型断言有时可以吗?
这个技能说,断言在某些情况下可以接受,但用来掩盖真正的问题时就很危险。
为什么要在应用的边界验证数据?
这个技能建议使用 Zod 等校验库检查外部数据,而不是对其类型做断言。
详情
作者的原始描述
Use when reviewing TypeScript files for type safety regressions, during code review of functions that handle external data, or when the codebase has ESLint warnings for @typescript-eslint/no-explicit-any.
热度
- GitHub 星标
- 75k
- 排名
- #2950
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。