microsoft / microsoft/TypeScript
Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 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
💻 Code
declare function makeRequest<
QueryParam
>(
getFn: (client: { prop: number }) => QueryParam,
params: NoInfer<QueryParam>,
): 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground and compare the two makeRequest calls in the issue’s Code section. Investigate contextual typing, transitively inferred return types, and NoInfer behavior; done means autocomplete suggests the relevant properties and the displayed parameter type agrees with the type used for validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100