TS4144: Indexed 类型必须有 类型 annotation
错误信息
类型的 computed 属性 name 必须是 唯一.
快速摘要
那里's issue 使用 computed 属性 or mapped 类型键. 键类型需要到 是 properly constrained.
为什么发生
Mapped 类型键 是不 properly constrained
Computed 属性 name 有无效类型
最小示例
✗ 错误代码
type Bad<T> = { [K in T]: string }; // TS4144: T not constrained✓ 修复代码
type Good<T extends string> = { [K in T]: string }; // ✅Constrain T 到字符串所以它 能是 used as mapped 类型键.
如何诊断
检查 mapped 类型语法
验证键 类型是 字符串, 数字, or symbol
如何修复
添加 proper 类型 constraints 到键
Fix mapped 类型语法