-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Template literals as keys in object literals loosing type information #41912
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
Comments
This is correct behavior, since you could write |
@RyanCavanaugh But this will not produce expected result either I won't get |
I don't understand what you mean by that. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh Sorry I wasn't clear enough. Here is a example of expected behavior. |
@falsyvalues I'v tried this, it seems work. const template = <T extends string>(name: T): Record<`${T}`, `${T}`> => ({
[`${name}`]: name,
} as any); |
Hi @dishuostec! Thanks for that. Looks returning type and |
Template literals as keys in object literals loosing type information, even with explicite type literals (works only with one exact type).
TypeScript Version: 4.1.2, 4.2.0-dev.20201210
Search Terms: Template literal types literal keys object keys literal types
Code
Expected behavior:
Actual behavior:
Playground Link: https://www.typescriptlang.org/play?ts=4.2.0-dev.20201210&ssl=13&ssc=26&pln=13&pc=44#code/MYewdgzgLgBFCmBbADgGwIYIPphFLA7iAE4DWAlmAOZboRanwCeMAvDADwAqM8AHgjAATCDGjFKVAHwAKMOkTwAXDC4BKNlJgyA3gCgYhmAG0ABgBId8xQF9TMOjFCQoAXRXX4em2oDcevWdoGAA3dFQAV3gcPEISCmo2OCQ0TGjcfCIySVp6RiYZAHIuAFEAZS5CvxgAehqncGCwyOUYHRM+FXFJdxgAIlKKvt8YGwCg2AQUDGwMuOzqQnIoAAssVGX4YnCsKCZkeCTuXgF4YVFu6llPFWLyypgAHxhCgHkAJUKnl4A5V8qNKwtLoDEYzJZPHYHKIJr1PN4-ONGrBmlEYpl4jkNghtqgklNUrNYlkEjQCMs1titjs9gcioMASM6g0XKFwlEVO1jJ0xFAJNRegN7sNRkjWQSZtESZIjjx+IIRLz+dI5ApWncKlVNNp9EYTBYrGqoY5YR41Qj-IFkWyWvNSfiUpK7ZJ6fcqkz6hMbRy2qp7iohUMRmMgA
Related Issues: Might be related to #41631
The text was updated successfully, but these errors were encountered: