Repository: TypeScript
Issue: Generic template literal index does not resolve value type
Labels: Suggestion,Awaiting More Feedback

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->

template string key generic "is not assignable to type" 

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This changed between versions 4.6.4 and 4.7.4

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.7.4#code/PTAEHkCMCsFMGMAuB1AlogFgVQHYBNYAnAZ3gHtDY8BpWAT2NHkoENFZGWdQyYFFQAdwxFYALgCwAKBCg5tBqBaVQmWKGKJCqHAHNGO0NQA0oWAA94sAA4DYLeBiHonXUAFd8RUhXXXKAGao5tKycgBqLAA27hxKKtFRoAAGWrHJ0hbWFAKIdNbqUHBIaJi4BCTklDT0xAA81Gbm7PiMmtp6AHygALygAN7ScnIA2gDWoIaNLIzJAPoAJP1jAL7JALpiqoSxANzSK-tSoWDoQhRjjIIuZO4CurA4RKjwxNIBnkioZNw4PwDij2e8AAKhxEAAKXjFFAucreKpUBTELZFfilbBeSq+GoMOoAIgCZDI+NAAB9QPjIMp8Z1TGN6FtCcTSRSqTSAJQDIZMH6aDQYW5RPAAIVgIJ24m2sV6PD4JThWJ81WRI3mSwZdDW6yOK2kJ1AkDuoD+AmumFADye2le70+iG+3CtwLBmgaTRaeDaWh0uk6UPlsLKSsRuJREEDGPh2JVtQadNAmq21C5gykclkAFEAErZ8DZyTp0CyEH5dQAcjRCuDFWVSLj1E6asW-Wo2vLk0YpqUxGIqF0OBYkCi6kQZFUZdA5bSsHLADoeWFQKWClOq0HMbXQ8j482lu1fe3OyayAIZn2B0OR6px3lV9PJfOeeQcPziIL3MKxRLYlsZ7LoXRRUtxxVV1WWehtV1IA)

### 💻 Code

```ts
// ObjectWithUnderscoredKeys creates an object where:
//   Keys are the strings in K, except each with an underscore prefix
//   Values are all `true`
export type ObjectWithUnderscoredKeys<K extends string> = {
    [k in K as `_${k}`]: true;
};

// it works without generics
function nonGenericTest(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys<"foo" | "bar">, key: "foo" | "bar") {
  const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`];
}

// but not with generics
function genericTest<K extends string>(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys<K>, key: K) {
  // ERROR:
  // Type 'ObjectWithUnderscoredKeys<K>[`_${K}`]' is not assignable to type 'true'.
  //   Type 'ObjectWithUnderscoredKeys<K>[`_${string}`]' is not assignable to type 'true'.
  const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`];
}
```

<!-- Please post the relevant code sample here as well-->

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->
In the generic function `genericTest`, indexing into the object doesn't yield a value with the type `true`.

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

In the generic function `genericTest`, indexing into the object should yield a value with the type `true`.

### Related issues

This 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.