Skip to content

Conversation

Andarist
Copy link
Contributor

fixes #62336

@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 08:08
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Aug 27, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 27, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where parameters were not being contextually typed when using an instantiated rest return mapper. The change allows the TypeScript compiler to properly infer parameter types in complex generic scenarios involving rest parameters.

Key Changes

  • Updates type inference logic in the checker to use return mapper when appropriate for rest type parameters
  • Adds a test case demonstrating the fixed contextual typing behavior

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/compiler/checker.ts Modifies type inference logic to combine return mapper with non-fixing mapper for rest type parameters
tests/cases/compiler/contextuallyTypeParametersUsingInstantiantedRestReturnMapper1.ts Adds test case for the contextual typing fix
tests/baselines/reference/contextuallyTypeParametersUsingInstantiantedRestReturnMapper1.types Baseline file showing expected type inference results
tests/baselines/reference/contextuallyTypeParametersUsingInstantiantedRestReturnMapper1.symbols Baseline file showing expected symbol resolution

): (...args: Args) => unknown;

call(
fn(function (a, b: number) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the presented case, there are no regular inference candidates for this rest because the return type candidate that could be gathered is only partially inferable ([a: string, b: silentNeverType]). That means it's treated as non-inferrable candidate and thus it's ignored.

But the return mapper manages to capture a [a: string, b: unknown] inference for the same Args.

So the proposal here is to utilize that mapping in the absence of regular candidates as that allows the inferrable part of the original partially candidate to be used when contextually typing parameters. Of course, that inferrable part is coming now from a completely different place (return mapper instead of that original partially inferrable candidate) - but conceptually they both used the information from the contextual signature so their "root origin" is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Function argument is not infered correctly
2 participants