microsoft / microsoft/TypeScript

Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type

Ouverte
#61,500 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Bug Domain: check: Contextual Types Help Wanted
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

### 🔎 Search Terms

contextually typed autocomplete, contextually typed type display, contextual return type

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=2&ssc=13&pln=3&pc=3#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwFsoBrEAJRAEdkQBnDAHgCh54BFGmATwAVYoCTAHwAKFvADmIDADFUALngjIWEKgyKA3vAAOMHDsWpkBAEYgY8AL4BKeAF4h7Tr34EANOJ1vaigHI4AJKoiBYMHBauMAJCnjaKAG44WMAA3ExMAPSZ8AASOAkWWKgS8AUW8AAGRKQU1HQYlfC0ABY4AO608BgtUBhVEdx80QRNWF3FoTBwwPBQXZVoxKgdqE1QqLOV3iO0Y104pvRqtFimEFzdXDogs-NVSyvta-DtLVhgLfDj3+h4EjBkDhkF12lget13l0wFAIBBvl0NvALPoYAA6Jg1chUGj0MSsVjKCCqdR2RzwFRqDCeAnwbLwACqpxKc2QGBwYBwBB0EGkCBaFgQtGQEik9C6K10+huMAwl1IXFoGNpmisnnpAD14ABBGASExUsqIK43eAAclVZoR8BW-XmpwkqCg5wQ7N0bj5lhwxrlpotUoMRhM5hgqWsZoxNnSmJI2PqePEhMp6i0AcMNuDFVsDicyepibpOSZxVKUDZHK5PL58AFcBtHWaIrFGC6CqVBdVcVSQA

### 💻 Code

```ts
declare function makeRequest<
QueryParam
>(
getFn: (client: { prop: number }) => QueryParam,
params: NoInfer,
): void;

// Hovering over `makeRequest` shows that `QueryParam` is inferred as `unknown` and `params` is obstensibly typed as `unknown` which is incongruous with this call is an error.
makeRequest(
(client) => client,
{}, // Using autocomplete in the object suggests no property keys.
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);

makeRequest(
(client: { prop: number }) => client,
{}, // Using autocomplete here now suggests keys.
);
```

### 🙁 Actual behavior

The first call to `makeRequest` where `client` is contextually typed has broken autocomplete. No relevant properties are suggested. Furthermore hovering over `makeRequest` shows, incongruously, that `params: unknown` and yet the call `{}` causes an error expecting it to be of type `{ prop: number; }`

### 🙂 Expected behavior

I expected auto-complete to work in all cases and the type display to be consistent.

### Additional information about the issue

Related to #46916 but @Andarist hypothesized that the underlying root cause is different in this case so I decided to open it as its own issue for tracking purposes.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le TypeScript Playground lié et comparez les deux appels à makeRequest dans la section Code de l’issue. Étudiez le typage contextuel, les types de retour inférés transitivement et le comportement de NoInfer ; le travail est terminé lorsque l’autocomplétion suggère les propriétés pertinentes et que le type de paramètre affiché correspond au type utilisé pour la validation.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.