Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed property invalid in type declaration emitted in d.ts file #60818

Open
dragomirtitian opened this issue Dec 19, 2024 · 0 comments
Open

Comments

@dragomirtitian
Copy link
Contributor

πŸ”Ž Search Terms

computed property unique symbols declaration emit

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.2#code/MYGwhgzhAEAq0G8BQ1XQgFzBglsaATgKZgAmA9gHYgCe0A2gEQaMC6AXNAK6U4COXIuhoBbAEbkQAbiQBfJCCIZoAD07I0DWExasO0Sl3FECM2TMXK6AXkQo09bczb6AjHKRA

πŸ’» 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant