Skip to content

Assign contextual parameter types to functions with type parameters #61792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jun 1, 2025

fixes #61791

@Copilot Copilot AI review requested due to automatic review settings June 1, 2025 08:25
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jun 1, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 1, 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 enables contextual typing for function expressions that introduce type parameters and updates related tests and compiler logic to reflect this change.

  • Updates fourslash tests to expect generic parameter T instead of any.
  • Adds new compiler tests covering contextual typing of generic functions and generators.
  • Removes exclusions for functions with type parameters in context-sensitivity checks.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

File Description
tests/cases/fourslash/contextualTypingGenericFunction1.ts Updated expected quickInfo for generic parameter contexts
tests/cases/compiler/contextualTypingGenericFunction2.ts Added new tests for contextual typing of functions with type params
src/compiler/utilities.ts Removed exclusion of type-parameterized functions from context checks
src/compiler/checker.ts Removed type-parameter guard in return-expression context check
Comments suppressed due to low confidence (2)

src/compiler/utilities.ts:10785

export function hasContextSensitiveParameters(node: FunctionLikeDeclaration): boolean {

src/compiler/checker.ts:21027

  • Add or update a comment explaining that functions with type parameters now participate in contextual return typing and why the node.typeParameters check was removed.
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {

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.

Parameters in functions with type parameters are not contextually-typed
2 participants