runtime-validation
它能做什么
这个技能找出应用从网络、存储、环境设置或表单接收数据的地方,并使用结构校验库添加运行时检查。它面向希望减少意外数据导致的错误的开发者。
适用场景
- ✓你请智能体为来自 API 或表单的数据添加检查的时候。
- ✓API 返回的数据结构与预期不同,导致应用出错的时候。
- ✓你在检查读取本地存储或环境变量的代码,并希望对这些值进行检查的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/runtime-validation/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“当 API 发送的数据与预期略有不同时,我的应用就会出错。请帮我在数据进入的地方添加检查吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出数据进入应用的地方,例如 fetch 调用、本地存储读取和表单提交。它会添加结构定义,例如使用 Zod,用来检查数据形状,并在不匹配时给出清晰的错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Validate external data at runtime with a schema library
TypeScript gives you confidence at compile time, but data from the network, user input, and storage arrives at runtime as raw, untyped values. A backend schema change, a misconfigured API, or malicious input can produce data that does not match your TypeScript types — and the compiler will never warn you. Runtime validation with a schema library catches these mismatches at the boundary, surfaces clear error messages, and prevents type-unsafe data from propagating through your application.
Quick Reference
- TypeScript types are compile-time only — they are completely erased at runtime
- API responses can differ from their declared types without causing a compile error
- A Zod schema simultaneously validates data and infers the TypeScript type
- Validate at trust boundaries only — not inside every internal function call
Check
Identify all places in this code where external data enters the application (fetch calls, localStorage reads, env variable access, form submissions) and report which ones lack runtime schema validation.
Fix
Add Zod schemas to validate the external data entry points in this code. Show the schema definition, the validated type inference, and where to call .parse() or .safeParse().
Explain
Explain why TypeScript types do not protect against runtime data mismatches, how Zod bridges compile-time and runtime safety, and when to use .parse() versus .safeParse().
Code Review
Review all external data entry points in this file: API calls, storage reads, environment variable access, and form handling. Flag any location where data is cast to a TypeScript type without a preceding runtime validation step.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/runtime-validation
常见问题
为什么 TypeScript 类型还不够?
这个技能说,TypeScript 类型在代码运行时会被移除,因此无法在运行时检查实际数据。
应该在哪里进行验证?
这个技能说,应在信任边界即外部数据进入的地方验证,而不是在每个内部函数中验证。
结构定义能给我带来什么?
这个技能说,Zod 结构定义既能检查数据,也能提供对应的 TypeScript 类型。
详情
作者的原始描述
Use when reviewing code that calls fetch(), reads from localStorage, accesses process.env, or processes form submissions without explicitly validating the incoming data shape.
热度
- GitHub 星标
- 75k
- 排名
- #3006
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。