microsoft / microsoft/TypeScript
Error message displays computed name '[attr]' instead of key value
未关闭
还没有人认领这个 Issue。
Experience Enhancement
Help Wanted
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
🔎 Search Terms
computed property, error message
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about computed properties
⏯ Playground Link
💻 Code
type Unit =
| {
name: string;
stength: number;
}
| {
name: string;
magic: number;
};
const createUnit = (
name: string,
attr: "strength" | "magic",
power: number,
): Unit => {
return attr === "strength"
? { name, [attr]: power } // <-- error here
: { name, [attr]: power };
};
🙁 Actual behavior
Error message displays "Object literal may only specify known properties, and '[attr]' does not exist in type 'Unit'".
🙂 Expected behavior
Error message should display that "strength" doesn't exist on Unit. (and possibly even recommend "stength" instead)
Additional information about the issue
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在链接的 Playground 中复现 TypeScript 代码示例的诊断,并将实际的 '[attr]' 消息与预期的 'strength' 措辞进行比较。跟踪编译器中计算属性错误报告的路径,并为所示示例添加覆盖,包括建议的 'stength' 拼写(如果支持)。当诊断报告解析后的键值而不是源表达式时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100