[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7DMHGFGH2YT86WQ6A53693W":3,"skill-same:01M7DMHGFGH2YT86WQ6A53693W":54},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":34,"install":35,"resources":47},"01M7DMHGFGH2YT86WQ6A53693W","typescript-best-practices",null,"TypeScript 最佳实践。读取或编辑任意 .ts 或 .tsx 文件时使用。","fenfenxu\u002Fpstack-zh","fenfenxu","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F2194243?v=4","01M7DMDSWBASX3NXC18FPHDJ8G","01M7DMDSWV8ASCZ4PH6YFXHPSJ",3,"MIT","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Ftypescript-best-practices\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: typescript-best-practices\ndescription: TypeScript 最佳实践。读取或编辑任意 .ts 或 .tsx 文件时使用。\npaths: [\"**\u002F*.ts\", \"**\u002F*.tsx\"]\ndisable-model-invocation: true\n---\n\n# TypeScript 最佳实践\n\n先应用 **type-system-discipline** 原则 skill。\n\n| 规则 | 摘要 |\n|------|---------|\n| 可区分联合 | 用 `kind` 字面量 discriminant 建模变体，使不可能状态无法表示。不要可选字段大杂烩。 |\n| 品牌类型 | 用 `& { readonly __brand: \"X\" }` 标记原始类型，防止混用。边界处校验一次。品牌只能由实际执行验证的 type guard（`input is AgentId`）给出，不能靠 `as`。 |\n| 构造式建模 | 构造形状使非法值无法构造。非空用 `[T, ...T[]]`，偶长用 `[T, T][]`，区间用 `start` 加 `duration`。不是运行时 guard，不是 refinement 类型的愿望。 |\n| 最简全函数类型 | 对 `T[]` 的一切操作仍全函数时保持 `T[]`。仅当宽松类型迫使 `!`、强转或「不应发生」的 throw 时才加强为 `NonEmpty\u003CT>`。 |\n| `unknown` 优于 `any` | 外部数据是 `unknown`。 |\n| schema 先于 guard | 手写逐属性 type guard 前，用仓库的运行时 schema 库并从 schema 推断类型，如 `z.infer`。 |\n| 禁止 `as` 强转 | 每个 `as` 都是潜在的运行时崩溃。仅在校验后强转。 |\n| 收窄层次 | discriminant switch > `in` > `typeof`\u002F`instanceof` > 用户 type guard > `as`。 |\n| Type guard | 必须验证声称。撒谎的 guard 比 `as` 更糟，bug 藏在「安全」名字后。命名为 `isX` 或 `hasX`。 |\n| 穷尽性 | 在 default 分支内联 `const _exhaustive: never = x;`，新增变体时编译器报错。 |\n| `satisfies` 优于 `as` | 校验值而不拓宽字面量类型。 |\n| 边界校验 | 数据进入处解析为命名领域类型。`Record\u003Cstring, unknown>`（无论怎么拼）止于该 parse。内部信任类型。见 **boundary-discipline** 原则 skill。 |\n| 由 schema 派生类型 | 优先 `Pick`\u002F`Omit`\u002F`Parameters`\u002F`ReturnType`\u002F`Awaited`\u002F`typeof`，再声明新 interface。 |\n| 对象参数 | 传对象而非位置参数，参数顺序自文档化。热路径可跳过（每帧渲染、分词器、解析器）。 |\n| 真实测试 | 能跑真代码就不要 mock。优先框架真实测试原语加 leak\u002Fdisposable 检查，在运行构建中验证 UI。仅 mock 本地跑不了的东西。 |\n| 结构化遥测 | 优先结构化 logger 诊断，上下文足以凭 id 调试。上线代码不用 `console.log`。 |\n\n示例见 `references\u002Fpatterns.md`。\n","# TypeScript 最佳实践\n\n先应用 **type-system-discipline** 原则 skill。\n\n| 规则 | 摘要 |\n|------|---------|\n| 可区分联合 | 用 `kind` 字面量 discriminant 建模变体，使不可能状态无法表示。不要可选字段大杂烩。 |\n| 品牌类型 | 用 `& { readonly __brand: \"X\" }` 标记原始类型，防止混用。边界处校验一次。品牌只能由实际执行验证的 type guard（`input is AgentId`）给出，不能靠 `as`。 |\n| 构造式建模 | 构造形状使非法值无法构造。非空用 `[T, ...T[]]`，偶长用 `[T, T][]`，区间用 `start` 加 `duration`。不是运行时 guard，不是 refinement 类型的愿望。 |\n| 最简全函数类型 | 对 `T[]` 的一切操作仍全函数时保持 `T[]`。仅当宽松类型迫使 `!`、强转或「不应发生」的 throw 时才加强为 `NonEmpty\u003CT>`。 |\n| `unknown` 优于 `any` | 外部数据是 `unknown`。 |\n| schema 先于 guard | 手写逐属性 type guard 前，用仓库的运行时 schema 库并从 schema 推断类型，如 `z.infer`。 |\n| 禁止 `as` 强转 | 每个 `as` 都是潜在的运行时崩溃。仅在校验后强转。 |\n| 收窄层次 | discriminant switch > `in` > `typeof`\u002F`instanceof` > 用户 type guard > `as`。 |\n| Type guard | 必须验证声称。撒谎的 guard 比 `as` 更糟，bug 藏在「安全」名字后。命名为 `isX` 或 `hasX`。 |\n| 穷尽性 | 在 default 分支内联 `const _exhaustive: never = x;`，新增变体时编译器报错。 |\n| `satisfies` 优于 `as` | 校验值而不拓宽字面量类型。 |\n| 边界校验 | 数据进入处解析为命名领域类型。`Record\u003Cstring, unknown>`（无论怎么拼）止于该 parse。内部信任类型。见 **boundary-discipline** 原则 skill。 |\n| 由 schema 派生类型 | 优先 `Pick`\u002F`Omit`\u002F`Parameters`\u002F`ReturnType`\u002F`Awaited`\u002F`typeof`，再声明新 interface。 |\n| 对象参数 | 传对象而非位置参数，参数顺序自文档化。热路径可跳过（每帧渲染、分词器、解析器）。 |\n| 真实测试 | 能跑真代码就不要 mock。优先框架真实测试原语加 leak\u002Fdisposable 检查，在运行构建中验证 UI。仅 mock 本地跑不了的东西。 |\n| 结构化遥测 | 优先结构化 logger 诊断，上下文足以凭 id 调试。上线代码不用 `console.log`。 |\n\n示例见 `references\u002Fpatterns.md`。\n",{"name":5,"paths":23,"description":7,"disable-model-invocation":26},[24,25],"**\u002F*.ts","**\u002F*.tsx",true,"main","e4477188d43269545432a83e4ac5d0733a812d09","skills\u002Ftypescript-best-practices",0,"https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh","http:\u002F\u002Fpstack.ganhai.cloud","https:\u002F\u002Fgithub.com\u002Ffenfenxu","2026-10-21 12:14:41",{"source":8,"skillName":5,"commands":36,"prompt":46,"zipAvailable":26},[37,40,43],{"tool":38,"command":39},"npx","npx skills add fenfenxu\u002Fpstack-zh --skill typescript-best-practices",{"tool":41,"command":42},"bunx","bunx skills add fenfenxu\u002Fpstack-zh --skill typescript-best-practices",{"tool":44,"command":45},"pnpm","pnpm dlx skills add fenfenxu\u002Fpstack-zh --skill typescript-best-practices","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Ftypescript-best-practices\u002FSKILL.md",[48],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":52,"sourceHtmlUrl":53},"references\u002Fpatterns.md","REFERENCE","参考文档",8821,"https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Ftypescript-best-practices\u002Freferences\u002Fpatterns.md",[55,62,69,76,83,90],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M7DMHJV7QMEE1F43FFW98FV8","why","用于「为什么 X 是这样实现的」「为什么选了 Y」、设计理由、回归、事后复盘，或数据支撑的阈值问题。发现可用 MCP 并并行查询各证据类别（源码控制、工单跟踪、长文文档、实时聊天、基础设施可观测性、错误跟踪、产品分析数仓），然后返回带引用的决策与权衡解读。运行时行为请用 how。","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Fwhy\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":18},"01M7DMHHRSS2SCZN6HWSANBJ35","unslop","从任意写作中剔除 AI 痕迹。","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Funslop\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":18},"01M7DMHEA1EGG2D9XQ33N66GDS","technical-writing","分层技术写作标准：Diátaxis 结构、Google 开发者风格句子、STE 指令规则、Global English 句法。用于 \u002Ftechnical-writing，或撰写\u002F审查文档、RFC、README、PR 描述、commit message 时。","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Ftechnical-writing\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":18},"01M7DMHCEXE1YRDR6XC1RXBG76","teach","用平实语言解释一段工作，让人真正理解。运行 how 与 why skill，把发现织成一份清晰说明。用于「teach me this」「help me really understand X」「explain this change or subsystem to me」。","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Fteach\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":18},"01M7DMH9KNBP83SHAW4TGZ4713","tdd","仅当用户明确要求 TDD、失败测试或回归测试时使用，或 bug 有明显且廉价的本地测试目标时使用。测试路径不清、昂贵、偏集成或未要求时跳过。","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Ftdd\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":18},"01M7DMH7VJ55VC39J4K0SNXSA1","swarm","扇出 N 个并行 worker，收齐后返回一份报告。用于 \u002Fswarm、「swarm this」，或并行覆盖、race、gauntlet 与探索。","https:\u002F\u002Fgithub.com\u002Ffenfenxu\u002Fpstack-zh\u002Fblob\u002Fmain\u002Fskills\u002Fswarm\u002FSKILL.md",[],[]]