Skip to content

Allow parameters to be contextually-typed based on contextual rest instantiated using return mapper#62341

Closed
Andarist wants to merge 3 commits intomicrosoft:mainfrom
Andarist:contextual-parameter-type-using-rest-return-mapper
Closed

Allow parameters to be contextually-typed based on contextual rest instantiated using return mapper#62341
Andarist wants to merge 3 commits intomicrosoft:mainfrom
Andarist:contextual-parameter-type-using-rest-return-mapper

Conversation

@Andarist
Copy link
Copy Markdown
Contributor

fixes #62336

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
Copy Markdown
Contributor

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
Copy Markdown
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.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Dec 5, 2025
@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Function argument is not infered correctly

4 participants