Computed property invalid in type declaration emitted in d.ts file
#60,818 opened on 2024幎12æ19æ¥
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
computed property unique symbols declaration emit
ð Version & Regression Information
- This is the behavior in every version I tried
⯠Playground Link
ð» Code
class T {
static readonly ["t"]: unique symbol;
}
let x: {
[T["t"]]: number;
};
let y = {
[T["t"]]: 1
}
ð Actual behavior
The type of x has an error saying: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol'
The type of y is emitted in declaration files just like the type of x and causes an error in the d.ts file
ð Expected behavior
The type of x should be valid. If we use a non-computed property name, the type would be valid (let x: { [T.t]: number; }, Playground Link). Declaration emit should not emit invalid code.
Additional information about the issue
Probably fixed by #60052 since the limitation on computed property names in types goes away.