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

Add support for computed properties #305

Open
TrevorSayre opened this issue Oct 17, 2021 · 4 comments
Open

Add support for computed properties #305

TrevorSayre opened this issue Oct 17, 2021 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@TrevorSayre
Copy link

TrevorSayre commented Oct 17, 2021

type Letters = 'a' | 'b' | 'c' | 'd' | 'e';
type Numbers = 1 | 2 | 3;
type Chars = '$' | '_';

type Names = `${Letters}${Uppercase<Letters>}${Numbers}${Chars}`;

// Quick fix available
// so computed properties, transforms, and long lists work
const names: { [K in Names]: K } = {};
type Letters = 'a' | 'b' | 'c' | 'd' | 'e';
type Numbers = 1 | 2 | 3;
type Chars = '@' | '!'; // Difference is only this line

type Names = `${Letters}${Uppercase<Letters>}${Numbers}${Chars}`;

// Quick not available
const names: { [K in Names]: K } = {};

The last example works in WebStorm via "implement all members" and would be a welcome addition to VSCode. The quick fix for microsoft/TypeScript#28491 was implemented via microsoft/TypeScript#44576 and solved some use cases, but not this one.

The error output does already suggest all the missing properties. It seems like the data is available to execute a quick fix.

image

image

Such names should be usable:

image

Additionally, when the quick fix does work, it only adds the properties and sets values as undefined even when the value is known (as in the above examples).

image

image

This issue was inspired by this tweet:
https://twitter.com/majidrazvi/status/1449493443743391746

@tamj0rd2
Copy link
Owner

@TrevorSayre What's the expected outcome here? I suppose you'd want it to be populated with all of the different combinations?

@TrevorSayre
Copy link
Author

@TrevorSayre What's the expected outcome here? I suppose you'd want it to be populated with all of the different combinations?

That's correct. Ideally both the indicated property names and values (when known) instead of the current undefined value. The working examples show this.

@TrevorSayre
Copy link
Author

Updated the issue description for further clarity.

@tamj0rd2
Copy link
Owner

Thanks for updating with those details! I'll try to get around to it in the next couple of weeks. I'm not working with Typescript much anymore, so any contributions are welcome.

@tamj0rd2 tamj0rd2 added the help wanted Extra attention is needed label Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants