Skip to content

keyof does not work for computed property name of getter or setter #56880

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

Closed
upsuper opened this issue Dec 26, 2023 · 1 comment
Closed

keyof does not work for computed property name of getter or setter #56880

upsuper opened this issue Dec 26, 2023 · 1 comment

Comments

@upsuper
Copy link

upsuper commented Dec 26, 2023

πŸ”Ž Search Terms

keyof get computed name

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231226#code/C4TwDgpgBAYg9nAPAFShAHsCA7AJgZygG8BfAPigF5iAoKeqAJwgENc5sAbEKAbQGkoAS2xQA1hBBwAZlGQBdAFxR8wRiIDmAbhokdNUJCgAhFoxRpMOAsXJVaDKBojA+gkeMky58gBQBKZVV1bG1dLSA

πŸ’» Code

// This works.
type Foo<T extends {}> = {
    readonly [K in keyof T]: string;
};

// This doesn't.
type Bar<T extends {}> = {
    get [K in keyof T](): string;
};

πŸ™ Actual behavior

Bar doesn't compile. The compiler says:

A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
Property '[K in keyof' implicitly has type 'any', because its get accessor lacks a return type annotation.

πŸ™‚ Expected behavior

Both type declarations above should work in the same way.

Additional information about the issue

No response

@upsuper
Copy link
Author

upsuper commented Dec 26, 2023

I think this is a duplicate of #51890.

@upsuper upsuper closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2023
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