Repository: TypeScript
Issue: Autocompletion fails - unnecessarily narrow for inferred Generic
Labels: Suggestion,Help Wanted,Domain: Completion Lists,Experience Enhancement

# Bug Report

In the following example typescript IS able to judge the set of valid strings, (as shown by the compiler error), but somehow autocompletion from the language server CAN'T resolve that set. It resolves instead to the set of strings already populated, as shown below in screenshots from the typescript playground

![image](https://user-images.githubusercontent.com/159819/218310226-57e5e89f-c96b-4345-9d45-f5cb1dd63ece.png)

![image](https://user-images.githubusercontent.com/159819/218310244-41c1ad16-5866-443b-8ca8-0220ad5617c6.png)

![image](https://user-images.githubusercontent.com/159819/218310401-2fbbcf10-03e4-4334-854b-1422fed77074.png)

Ideally this approach should have editor autocompletion support constraining strings to type `Role`, NOT type `Evidenced`. The type `Evidenced` is actually inferred from the items being edited right now so the programmer should be able to draw from the broader set `Role`.

### 🔎 Search Terms

Autocompletion, inferred, generic, constraint, "too narrow"

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about inference

### ⏯ Playground Link

[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.9.5#code/MYewdgzgLgBASgeQDIFEDKMC8MDaAiAQwCcoBLaPAGhjwCMCBrAUyKpuALABMAbJ6UsAYBbRizwBdGAQgxQkWBAJkIAM1L94TAl3A8AngEEiRAvoA80IqTABzAHwBuAFBR9ABybwQfLDDeeIKrwyOg4YACuwrQsEi7OqhFgwGTg-gS25igAbqRcTMlMXDBMAB5QBVyycD5M9gAUzjAwqmAAXDD1TLn5hR31RLUdOXkFwEUAlFj2MNkgeVOYM3N5lE0wAHRbg3wQHTgjveNc1Fsbh2NFOBISzlMA3usA9E8w+aCmFS1g60RMUBEiGBOosZvdHABfFwQ5zOeTQN5MD7KIoAMWB2CgGUazXqoJg4Iha2ahBI5CgbDoYlY1DwHG4fDwdyAA)

### 💻 Code

```ts
const ROLES = ["artist", "baker", "candlestickmaker"] as const satisfies ReadonlyArray<string>;
type Role = typeof ROLES[number];

function tag<Evidenced extends Role>(
  fn: (evidence: (role: Evidenced) => void) => void,
  ...roles: [Evidenced, ...Evidenced[]]
) {
  // decorate fn
  return () => {;};
}

const decoratedFn = tag(
  () => {;},
  "artist", "baker", "candle"
)
```

### 🙁 Actual behavior

The set of strings for autocompletion is initially empty, when it should be populated by `Role`. After one or more entries have been provided to the list, it then autocompletes only to strings which are already provided.

### 🙂 Expected behavior

The set of strings for autocompletion of the arguments to the `tag` function should be populated by `Role`

### Background

The motivating example is within a portfolio of narrative content ([interactive fiction-style](https://github.com/cefn/cloak-of-darkness/blob/63b9e3b039be89106af33a8da3615944da90d6d5/src/stories/cloak-of-darkness.tsx)) using Generator functions. This wrapper function defines a composition function type to evidence roles either by invoking the callback between yields (when a yielded narrative references that role), or if that hasn't happened by calling the callback for those roles when the function eventually returns (allowing very terse definitions for simple narratives without requiring inline callbacks). 

This ensures that not referencing at least one role is an error, and offers the delight that narrative elements which touch on some role can lead to an immediate update of the displayed model (showing which roles have been evidenced). 

The central purpose of this typing is to assist with editor support, so not being able to have autocompletion is a real dead-end.