René's URL Explorer Experiment


Title: Template literal index does not transform the key and value types. · Issue #48983 · microsoft/TypeScript · GitHub

Open Graph Title: Template literal index does not transform the key and value types. · Issue #48983 · microsoft/TypeScript

X Title: Template literal index does not transform the key and value types. · Issue #48983 · microsoft/TypeScript

Description: Bug Report I have a data store that uses prefixes to store different types of data. One of the types is "preferences". data = { "preferences.a": string, "preferences.b": number } I have a getter interface for preferences that allows the ...

Open Graph Description: Bug Report I have a data store that uses prefixes to store different types of data. One of the types is "preferences". data = { "preferences.a": string, "preferences.b": number } I have a getter in...

X Description: Bug Report I have a data store that uses prefixes to store different types of data. One of the types is "preferences". data = { "preferences.a": string, "preferences.b"...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/48983

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Template literal index does not transform the key and value types.","articleBody":"# Bug Report\r\n\r\nI have a data store that uses prefixes to store different types of data.  One of the types is \"preferences\".\r\n\r\n```\r\ndata = {\r\n  \"preferences.a\": string,\r\n  \"preferences.b\": number\r\n}\r\n```\r\n\r\nI have a getter interface for preferences that allows the user to query without the prefix:\r\n\r\n```\r\ntype PreferencesSchema = {\r\n  a: string,\r\n  b: number\r\n}\r\nfunction getPreference\u003cKeyT extends keyof PreferencesSchema>(key: KeyT): PreferencesSchema[KeyT] {\r\n  return data[`preferences.${key}`];\r\n} \r\n```\r\n\r\nUnfortunately, this gives an error, because TS looks for `a` and `b` on the `data` instead of the actual indexes `preferences.a` and `preferences.b`.  I understand template literal types are relatively new, but I think in this case, the compiler should see that the prefixed keys are being used and that the associated values are the same as the value types in the preference schema.\r\n\r\nI found a similar looking issue: https://github.com/microsoft/TypeScript/issues/13948, but I don't think this error can be attributed to type-widening.\r\n\r\n### 🔎 Search Terms\r\n\r\ntemplate literal missing properties\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.3.5 and 4.4.4 (4.3.5 still gives a `noImplicitAny` error, but the introduction of template literal types makes this issue arise even without strict checks)\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.6.2#code/C4TwDgpgBACgThAZhBA7AxhAzgZXQCwgFsBDKAXigG8BYAKCihIC4otg4BLVAcwBp6jAEatUAVyJCU9AL7163YCkQlMUACIlgJPIVLVBUAERgEyNJiwA6EkdbsuvAQ2OmkKCBmxWhdqOMlpOjk6enQAe1R2KAATLRYNeN1iMkpaFxMzDy9rW1YjQgAbQvCoAHdwuEKYo2dGTPcLb19WAEYAJgBmABYAVll5OgB6IahgQihOLCwxCHpEMQxgTkioHghgeEbPTAAeAGkIEAAVKAgADyVUGKwoAGsj8MRYLKbcAhSAPgAKB5BWQ4nACUrC25h22GSpAA2oDjgBdAwuBDAMRwVCxeLQgAGbnBOSsABIqH8ZNj4QBuWRQQYjcqVO4kODhRYxeaLdDLVYVOB3bg8ADiGzB2T2cLOl08N3uj2eIreUJIPz+AKOxxBiW0ipxeNF3mJcLJiPSjBRaIxcW0OteEOsxNJ5KpwSAA)\r\n\r\n### 💻 Code\r\n\r\n```\r\ntype PreferencesSchema = {\r\n  a: string,\r\n  b: number\r\n}\r\n\r\ninterface DataSchema {\r\n  \"preferences.a\": string,\r\n  \"preferences.b\": number\r\n}\r\n\r\nconst data: DataSchema = {\r\n  \"preferences.a\": \"hello world\",\r\n  \"preferences.b\": 12345\r\n}\r\n\r\n// the issue\r\nfunction getPreference\u003cKeyT extends keyof PreferencesSchema>(key: KeyT): PreferencesSchema[KeyT] {\r\n  return data[`preferences.${key}`];\r\n} \r\n\r\n// workaround\r\nfunction workingGetPreference\u003cKeyT extends keyof PreferencesSchema>(key: KeyT): DataSchema[`preferences.${KeyT}`] {\r\n  return data[`preferences.${key}`];\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nAn error occurs:\r\n\r\n```\r\nType 'DataSchema[`preferences.${KeyT}`]' is not assignable to type 'PreferencesSchema[KeyT]'.\r\n  Type 'DataSchema' is missing the following properties from type 'PreferencesSchema': a, b\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nTypeScript should recognize that `preferences.a`/`preferences.b` is being used as an index, not `a`/`b`.  Therefore it shouldn't matter that `DataSchema` is missing `a` and `b` as properties.","author":{"url":"https://github.com/benjaminpjones","@type":"Person","name":"benjaminpjones"},"datePublished":"2022-05-06T03:12:53Z","url":"https://github.com/microsoft/TypeScript/issues/48983"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:bafe3342-5861-56d9-7559-f32f65412455
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC3E0:4BB79:222D5E5:2B9E48F:6B0182E0
html-safe-noncebd536358ed7e1ce141a11bb8e48ffe880e25468a0e9372bb7ce0f59224f2bc3b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0UwOjRCQjc5OjIyMkQ1RTU6MkI5RTQ4Rjo2QjAxODJFMCIsInZpc2l0b3JfaWQiOiIyMjAwNTQ4MTY4MzA1ODM2NzY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac573367ae8c9e3fe39a1d5e094c30506ba2ff49d0cfdbaf3b3b14462d27846750
hovercard-subject-tagissue:1227369532
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/48983/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0c0e3668599d7ebb573c654ccae9f8af06134eb565160d121040cda8ac31b426/microsoft/TypeScript/issues/48983
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0c0e3668599d7ebb573c654ccae9f8af06134eb565160d121040cda8ac31b426/microsoft/TypeScript/issues/48983
og:image:altBug Report I have a data store that uses prefixes to store different types of data. One of the types is "preferences". data = { "preferences.a": string, "preferences.b": number } I have a getter in...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebenjaminpjones
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/48983#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F48983
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F48983
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/48983
Reloadhttps://github.com/microsoft/TypeScript/issues/48983
Reloadhttps://github.com/microsoft/TypeScript/issues/48983
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/48983
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/48983
Template literal index does not transform the key and value types.https://github.com/microsoft/TypeScript/issues/48983#top
https://github.com/ahejlsberg
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
https://github.com/benjaminpjones
Benjamin Jones (benjaminpjones)https://github.com/benjaminpjones
on May 6, 2022https://github.com/microsoft/TypeScript/issues/48983#issue-1227369532
#13948https://github.com/microsoft/TypeScript/issues/13948
Playground link with relevant codehttps://www.typescriptlang.org/play?ts=4.6.2#code/C4TwDgpgBACgThAZhBA7AxhAzgZXQCwgFsBDKAXigG8BYAKCihIC4otg4BLVAcwBp6jAEatUAVyJCU9AL7163YCkQlMUACIlgJPIVLVBUAERgEyNJiwA6EkdbsuvAQ2OmkKCBmxWhdqOMlpOjk6enQAe1R2KAATLRYNeN1iMkpaFxMzDy9rW1YjQgAbQvCoAHdwuEKYo2dGTPcLb19WAEYAJgBmABYAVll5OgB6IahgQihOLCwxCHpEMQxgTkioHghgeEbPTAAeAGkIEAAVKAgADyVUGKwoAGsj8MRYLKbcAhSAPgAKB5BWQ4nACUrC25h22GSpAA2oDjgBdAwuBDAMRwVCxeLQgAGbnBOSsABIqH8ZNj4QBuWRQQYjcqVO4kODhRYxeaLdDLVYVOB3bg8ADiGzB2T2cLOl08N3uj2eIreUJIPz+AKOxxBiW0ipxeNF3mJcLJiPSjBRaIxcW0OteEOsxNJ5KpwSAA
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on May 6, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1119638098
#30581https://github.com/microsoft/TypeScript/issues/30581
#47109https://github.com/microsoft/TypeScript/pull/47109
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on May 6, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1119799318
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on May 6, 2022https://github.com/microsoft/TypeScript/issues/48983#event-6564851649
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on May 6, 2022https://github.com/microsoft/TypeScript/issues/48983#event-6564851994
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 4.8.0https://github.com/microsoft/TypeScript/milestone/163
on May 6, 2022https://github.com/microsoft/TypeScript/issues/48983#event-6564852226
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on May 9, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1120958814
https://github.dev/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/compiler/checker.ts#L19410-L19416https://github.dev/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/compiler/checker.ts#L19410-L19416
https://github.dev/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/compiler/checker.ts#L19440https://github.dev/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/compiler/checker.ts#L19440
https://github.dev/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/compiler/checker.ts#L19445https://github.dev/microsoft/TypeScript/blob/1071240907ab7aae63ecc9c0bbde42aa51dc7669/src/compiler/checker.ts#L19445
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on May 22, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1133929582
#47109https://github.com/microsoft/TypeScript/pull/47109
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on May 22, 2022https://github.com/microsoft/TypeScript/issues/48983#event-6656364469
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
TypeScript 4.8.0https://github.com/microsoft/TypeScript/milestone/163
on May 22, 2022https://github.com/microsoft/TypeScript/issues/48983#event-6656364527
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on May 22, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1133945122
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
TS playgroundhttps://www.typescriptlang.org/play?ts=4.8.0-dev.20220522#code/C4TwDgpgBACgThAZhBA7AxhAzgZXQCwgFsBDKAXigG8BYAKCihIC4otg4BLVAcwBp6jAEatUAVyJCUAugF969UJCgAREsBJ5CpADwAVAHwVqUANowo3KAGsIIAPaIoepligADMAmRpMWAHQAJFQWAGRsHNw8su4Auqx65rFQ8nT06Pao7FAAJuosqvlaxCQ68EgoEBjYxaRGlLQMUABEXhW+2P4kzazNhAA2-fZQAO72cP05zTKMrd6V1QFCPVAAjABMAMwALACs9Kn0iGIYwJyZUDwQwOU+VZg6ANJQEAAewFU5brYOTrcLflqJAMAAofqxHgBKVj-Dq4AglUyPZKNRgIYBiOCoXL5UyeeZwoJUH4xWIAbgOUCAA
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on May 23, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1134049714
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on May 23, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1134318780
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on May 25, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1137793095
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on May 25, 2022https://github.com/microsoft/TypeScript/issues/48983#event-6680741449
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on May 25, 2022https://github.com/microsoft/TypeScript/issues/48983#issuecomment-1137817352
microsofthttps://github.com/microsoft
on Oct 22, 2025https://github.com/microsoft/TypeScript/issues/48983#event-20417536051
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/48983
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/48983
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.