-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inferring type from Record where keys are template literal types should return correct value type #42159
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
The definition of type Record<K extends keyof any, T> = {
[P in K]: T;
}; which is a mapped type that creates a property for every constituent of This will be fixed if #26797 is merged, because template literal types will be allowed as an index signature parameter. |
@andrewbranch thanks for clear explanation! i hope the PR will eventually get merged :D |
Me too! π |
@andrewbranch could this issue be reopened? |
It doesn't report an error for that? |
Yeah, because thatβs the version of TypeScript that we were on when the issue was reported π |
π€£ ah sorry, I thought it would take the latest by default |
Haha no worries, I think it depends on whether or not the TS version is explicitly encoded into the URL |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
π Search Terms
Found #29718 but not sure if it is the same error
π Version & Regression Information
TypeScript v4.2.0-dev.20201230
β― Playground Link
https://www.typescriptlang.org/play?ts=4.2.0-dev.20201230#code/PTAEBcE8AcFNQMIHsA2SBOoC8oDO50BLAOwHNQRQAVAC0N1AHcMBrXAKCjkVQ21AAGAY17oAJAG98RMgF8BnGPGRp0DHACVYI9ABMAPCowAaPARKkAfAG527EcXygRq3AC4er-hPag-oAHIXDAAhFABXWACPALDIgONff0oAZRokcJRdUGh0JABbaHBQWHQ89AB+JL8AkgA3AEMUQl1owK1WxNk7ShCAVQBxADpnUVASADNShnAkQXDiFiRGYgFxx3BYBuykCcFpCwEh+yQN0dV+UlhwAGlYSAA1JsiACmC1UyDROKiASjsJgshOBCKdQFdbvcnhFYPoklQSgAPTbEXQMLQ6AwHMimBYsYjLYiWRJ+G5IlFo0Ase67ajsSwvJAAIwAVh4qKZqZAPDdfuyANo3AC6oB8fnQ13C6GIoGZLP5XKFtm6QA
π» Code
π Actual behavior
getKeyValue(colors, 'colorBlue')
infersunknown
'invalid': 'Red',
is still valid key forcolors: Colors
π Expected behavior
getKeyValue(colors, 'colorBlue')
should inferstring
return value'invalid': 'Red',
should prompt an error as it does not match template literal typeThe text was updated successfully, but these errors were encountered: