microsoft / microsoft/TypeScript
Error message displays computed name '[attr]' instead of key value
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic from the TypeScript code sample in the linked Playground and compare the actual '[attr]' message with the expected 'strength' wording. Trace the computed-property error reporting path in the compiler and add coverage for the shown example, including the suggested 'stength' spelling if supported. Done means the diagnostic reports the resolved key value rather than the source expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100