·iterate-objects-safely
</>

iterate-objects-safely

marius-townhouse/effective-typescript-skills

在迭代对象键和值时使用。当 for...in 循环产生类型错误时使用。当 Object.entries 返回任何类型时使用。在处理原型污染问题时使用。在考虑地图与对象时使用。

2安装·0热度·@marius-townhouse

安装

$npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill iterate-objects-safely

SKILL.md

Iterating over objects in TypeScript is surprisingly tricky. The for...in loop infers keys as string rather than the object's keys, leading to indexing errors. This happens because objects can have additional properties beyond their declared type (structural typing), and for...in includes inherited properties.

Understanding safe iteration patterns helps you avoid any types and type assertions while correctly handling object traversal.

Use Object.entries for safe iteration over any object. Use for...in with keyof assertions only when you know the exact shape. Consider Map for guaranteed type safety.

在迭代对象键和值时使用。当 for...in 循环产生类型错误时使用。当 Object.entries 返回任何类型时使用。在处理原型污染问题时使用。在考虑地图与对象时使用。 来源:marius-townhouse/effective-typescript-skills。

查看原文

可引用信息

为搜索与 AI 引用准备的稳定字段与命令。

安装命令
npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill iterate-objects-safely
分类
</>开发工具
认证
收录时间
2026-02-05
更新时间
2026-02-18

快速解答

什么是 iterate-objects-safely?

在迭代对象键和值时使用。当 for...in 循环产生类型错误时使用。当 Object.entries 返回任何类型时使用。在处理原型污染问题时使用。在考虑地图与对象时使用。 来源:marius-townhouse/effective-typescript-skills。

如何安装 iterate-objects-safely?

打开你的终端或命令行工具(如 Terminal、iTerm、Windows Terminal 等) 复制并运行以下命令:npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill iterate-objects-safely 安装完成后,技能将自动配置到你的 AI 编程环境中,可以在 Claude Code 或 Cursor 中使用

这个 Skill 的源码在哪?

https://github.com/marius-townhouse/effective-typescript-skills