principle-type-system-discipline
它能做什么
为智能体提供一条设计类型、尽早发现错误的规则。适合使用静态类型语言的开发者。
适用场景
- ✓当你设计类型或审阅函数签名的时候。
- ✓当两个值共享同一类型,却代表不同含义的时候。
- ✓当来自程序外部的数据进入代码的时候。
技能链接
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-type-system-discipline/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们的用户 ID 和订单 ID 都是普通字符串,经常被混淆。请收紧类型,让编译器阻止这种情况。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会为每个语义值赋予自己的类型,在边界处把外部数据解析为带类型的模型,让未处理的变体导致构建失败,并从权威的模式定义中推导类型,而不是手写副本。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Type System Discipline
Make the compiler reject impossible states, mismatched primitives, and unhandled variants. Prefer defining errors and special cases out of existence over proliferating handlers. For TypeScript syntax, see the typescript-best-practices skill.
- Brand semantic primitives.
UserIdandOrderIdare strings underneath but should not be interchangeable. Give each its own type, such as a branded intersection in TypeScript or a newtype elsewhere. Validate once at creation, trust the type downstream. If two arguments share a primitive type but mean different things, brand them. - External data is untyped until parsed. RPC payloads, JSON, IPC messages, CLI args, config files, environment variables, database rows. Have a parse function at every boundary that turns unstructured input into the typed model. The boundary-discipline principle skill says where to put validation.
- Derive types from authoritative schemas. When a protocol buffer, OpenAPI spec, GraphQL schema, database migration, design-token file, or another file owns a shape, derive from it instead of hand-rolling a parallel type. See the encode-lessons-in-structure principle skill.
常见问题
什么是品牌类型?
一种底层看似字符串、却不能与其他 ID 混用的类型,这样编译器就能捕获这类错误。
解析发生在哪里?
在每个边界处,例如网络负载、配置文件、命令行参数和数据库行。
为什么要从模式定义中推导类型?
这样由协议文件或迁移定义的结构就不会被手工复制而逐渐产生偏差。
详情
作者的原始描述
Apply when designing types, reviewing a function signature, or writing code in any statically-typed language. Make illegal states unrepresentable, brand semantic primitives, parse external data at boundaries, exhaust variants, derive from authoritative schemas.
repo: cursor/plugins
热度
- GitHub 星标
- 15k
- 排名
- #10991
- 许可证
- —
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
advisor
15k如果你开启该功能,让你的智能体在关键节点咨询一个更强的第二模型,例如在重大决定之前,或在错误上卡住时。
check-agent-compatibility
15k全面检查 AI 编程智能体能否启动、验证和记录某个代码仓库,并返回一个兼容性评分以及主要问题。
cli-for-agents
15k教你的智能体设计或审查命令行工具,使 AI 智能体无需提示即可运行,并提供清晰的帮助文字和示例。
continual-learning
15k通过把回顾过往对话的工作交给专门的记忆更新程序,使你的 AGENTS.md 笔记保持最新。