Contextual typing for return expressions of functions with contextual signatures based on instantiated types#61185
Open
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Conversation
… signatures based on instantiated types
Contributor
Author
|
@jakebailey would you be so kind and run tests here? :) |
9055e55 to
a45dfbb
Compare
Andarist
commented
Feb 16, 2025
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)); |
Contributor
Author
There was a problem hiding this comment.
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.
…-for-returns-of-contextual-signatures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This expands on #30568 (in a way)
fixes #61197