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
- I was unable to test this on prior versions because unlikely to be differenct
⏯ Playground Link
Playground link example giving error message
💻 Code
const s=Symbol('foo')
const sf=Symbol.for('foo')
class C1 {
static readonly ['foo']:Record<string,any>
static readonly [s]: Record<string,any>
static readonly [sf]: Record<string,any>
static readonly [Symbol.for('foo')]: Record<string,any> // ts1166
}
declare var o: {prop: 'foo'};
class C2 {
[o.prop] = 1; // works
[(o).prop] = 1; // ts1166, adding parens gives an error because it's syntactically no longer a dotted name
}
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.
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.