microsoft / microsoft/TypeScript
Broken property suggestions due to a successfully contextually typed function
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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 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
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 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