Title: Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript · GitHub
Open Graph Title: Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript
X Title: Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript
Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript
Open Graph Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript
X Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript
Opengraph URL: https://github.com/microsoft/TypeScript
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic template literal index does not resolve value type","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\n\r\ntemplate string key generic \"is not assignable to type\" \r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- This changed between versions 4.6.4 and 4.7.4\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.7.4#code/PTAEHkCMCsFMGMAuB1AlogFgVQHYBNYAnAZ3gHtDY8BpWAT2NHkoENFZGWdQyYFFQAdwxFYALgCwAKBCg5tBqBaVQmWKGKJCqHAHNGO0NQA0oWAA94sAA4DYLeBiHonXUAFd8RUhXXXKAGao5tKycgBqLAA27hxKKtFRoAAGWrHJ0hbWFAKIdNbqUHBIaJi4BCTklDT0xAA81Gbm7PiMmtp6AHygALygAN7ScnIA2gDWoIaNLIzJAPoAJP1jAL7JALpiqoSxANzSK-tSoWDoQhRjjIIuZO4CurA4RKjwxNIBnkioZNw4PwDij2e8AAKhxEAAKXjFFAucreKpUBTELZFfilbBeSq+GoMOoAIgCZDI+NAAB9QPjIMp8Z1TGN6FtCcTSRSqTSAJQDIZMH6aDQYW5RPAAIVgIJ24m2sV6PD4JThWJ81WRI3mSwZdDW6yOK2kJ1AkDuoD+AmumFADye2le70+iG+3CtwLBmgaTRaeDaWh0uk6UPlsLKSsRuJREEDGPh2JVtQadNAmq21C5gykclkAFEAErZ8DZyTp0CyEH5dQAcjRCuDFWVSLj1E6asW-Wo2vLk0YpqUxGIqF0OBYkCi6kQZFUZdA5bSsHLADoeWFQKWClOq0HMbXQ8j482lu1fe3OyayAIZn2B0OR6px3lV9PJfOeeQcPziIL3MKxRLYlsZ7LoXRRUtxxVV1WWehtV1IA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\n// ObjectWithUnderscoredKeys creates an object where:\r\n// Keys are the strings in K, except each with an underscore prefix\r\n// Values are all `true`\r\nexport type ObjectWithUnderscoredKeys\u003cK extends string> = {\r\n [k in K as `_${k}`]: true;\r\n};\r\n\r\n// it works without generics\r\nfunction nonGenericTest(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys\u003c\"foo\" | \"bar\">, key: \"foo\" | \"bar\") {\r\n const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`];\r\n}\r\n\r\n// but not with generics\r\nfunction genericTest\u003cK extends string>(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys\u003cK>, key: K) {\r\n // ERROR:\r\n // Type 'ObjectWithUnderscoredKeys\u003cK>[`_${K}`]' is not assignable to type 'true'.\r\n // Type 'ObjectWithUnderscoredKeys\u003cK>[`_${string}`]' is not assignable to type 'true'.\r\n const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`];\r\n}\r\n```\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n\r\n### 🙁 Actual behavior\r\n\r\n\u003c!-- What happened, and why it was wrong -->\r\nIn the generic function `genericTest`, indexing into the object doesn't yield a value with the type `true`.\r\n\r\n### 🙂 Expected behavior\r\n\r\n\u003c!-- What you expected to happen instead, and why -->\r\n\r\nIn the generic function `genericTest`, indexing into the object should yield a value with the type `true`.\r\n\r\n### Related issues\r\n\r\nThis seems similar to https://github.com/microsoft/TypeScript/issues/48983, but that was marked as `Working as intended` and the behavior in this example doesn't seem like it should be intended.\r\n","author":{"url":"https://github.com/zachkirsch","@type":"Person","name":"zachkirsch"},"datePublished":"2022-07-25T00:42:18Z","url":"https://github.com/microsoft/TypeScript/issues/50030"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:3a2941d7-5ec8-2859-533e-64c2ddae23ca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF94:2C69FC:1D7E9:2663B:6B017E23 |
| html-safe-nonce | 18d7f36b688a1d7a768a329d82cd6003a6371d3e6cbdd5eaf99c1ed709c9e3ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjk0OjJDNjlGQzoxRDdFOToyNjYzQjo2QjAxN0UyMyIsInZpc2l0b3JfaWQiOiIyNzc2MDYxNzE3MTExNzMzNzk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 18ebe41586cff939167cd2d0924e13e78e0723c1ac932c7dd229570f540cf1fa |
| hovercard-subject-tag | repository:20929025 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/microsoft/TypeScript/issues/50030 |
| twitter:image | https://opengraph.githubassets.com/47cde802d3847ff7ce61448bd4f8c3272d012c9a3f2b9085b71a67530bf7bbd6/microsoft/TypeScript |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47cde802d3847ff7ce61448bd4f8c3272d012c9a3f2b9085b71a67530bf7bbd6/microsoft/TypeScript |
| og:image:alt | TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generic template literal index does not resolve value type · Issue #50030 · microsoft/TypeScript |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-cache |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width