Skip to content
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

Contextual typing for return expressions of functions with contextual signatures based on instantiated types #61185

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Feb 15, 2025

This expands on #30568 (in a way)
fixes #61197

@Andarist
Copy link
Contributor Author

@jakebailey would you be so kind and run tests here? :)

@Andarist Andarist force-pushed the fix/contextual-typing-for-returns-of-contextual-signatures branch from 9055e55 to a45dfbb Compare February 16, 2025 19:49
Comment on lines +31977 to +31987
// prevent inference candidates of outer inference context to provide contextual type information for the expressions within the inner context
// that could turn fresh literal candidates in the inner context into regular types for union-like literals (such as booleans and enums)
// and that would create mismatches between inferred types for outer and inner contexts which is especially problematic when invariant type parameters are involved
//
// the call below should be ok but with the inner one receiving `boolean` as contextual type it would infer `true` for its type parameter
// and that would create outer signature applicability error with outer `Box<boolean>` and inner `Box<true>`
//
// interface Box<T> { v: (arg: T) => T; }
// declare function invariantBox<T>(v: T): Box<T>
// declare function fn<T>(arg: Box<T>, get: () => Box<T>): void;
// fn(invariantBox(true), () => invariantBox(true));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this problem is quite similar to #48363 , #59754 and #61196

So it feels like some consistent approach could be used to fix those and to remove this branch. But that problem is out of the scope of this PR so I'm not attempting to deal with it. Thanks to this branch the behavior should be no worse than the existing one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not started
1 participant