Improve error messages for computed class property names #42619
Labels
Domain: Error Messages
The issue relates to error messaging
Experience Enhancement
Noncontroversial enhancements
Good First Issue
Well scoped, documented and has the green light
Help Wanted
You can do this
Milestone
Bug Report
🔎 Search Terms
"A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. "
"ts(1166)"
🕗 Version & Regression Information
⏯ Playground Link
Playground link example giving error message
💻 Code
See this closed issue for the source the examples, and the reasoning why error (ts1166) is reasonable enough in both cases (although the error message content is not reasonably straightforward).
🙁 Actual behavior
Error message: ts1166
"A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. "
🙂 Expected behavior
An error message like
"A computed property name in a class property declaration must be
a straightforward expression for a literal string or a literal number, or a constant reference to a symbol. "
"Straightforward" is obviously not a complete description, but it is accurate and fits in the error message.
Error ts1166 is clearly generated during syntax parsing, so claims about 'type' are bound to be wrong when the type is obscured by non-straightforward syntax.
BTW, 'unique symbol type' seems to be an alias for 'type of a literal symbol`, and isn't particularly helpful - every symbol instance is unique, just like every object is unique, and (AFAIK but I could be wrong) 'unique object type' is not a standard phrase. But ts1166 doesn't need to mention type anyway.
The text was updated successfully, but these errors were encountered: