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