microsoft / microsoft/TypeScript

Broken property suggestions due to a successfully contextually typed function

Open
#63,787 1 comment 1 reaction 0 assignees View on GitHub
Bug
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

```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 here suggests globals, not `prop` like it should.
{},
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);

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

Sub-part of https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2759515773 with parts pointed out with https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648

See @Andarist's analysis at https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648

Contributor guide

Open the contributing guide

Research direction

Start with the minimal TypeScript reproduction in the issue and read the linked analysis in issue #46916 and its comments. Trace contextual typing and inference for the generic function, then verify that QueryParam is inferred from the callback and that autocomplete for params offers prop without an explicit callback annotation.

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
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.