Improve contextual typing by generic rest parameters#30114
Merged
ahejlsberg merged 4 commits intomasterfrom Feb 28, 2019
Merged
Improve contextual typing by generic rest parameters#30114ahejlsberg merged 4 commits intomasterfrom
ahejlsberg merged 4 commits intomasterfrom
Conversation
weswigham
reviewed
Feb 27, 2019
| // outer call expression. Effectively we just want a snapshot of whatever has been | ||
| // inferred for any outer call expression so far. | ||
| const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); | ||
| const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), InferenceFlags.NoDefault)); |
Member
There was a problem hiding this comment.
The cloneTypeMapper call used to create the returnType mapper inside call resolution doesn't pass InferenceFlags.NoDefault with this change. Intentional?
Member
Author
There was a problem hiding this comment.
Yes, it's intentional. We only want the InferenceFlags.NoDefault behavior here (because we're transposing inferences from the outer call mapper and don't want an absence of inferences in the outer mapper to turn into what appears to be a concrete inference of the default).
weswigham
approved these changes
Feb 28, 2019
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 PR improves contextual typing by generic rest parameters such that we can infer a tuple type from the function expression or arrow function being contextually typed while simultaneously assigning contextual parameter types to the function expression or arrow function. Consider:
In the examples above, the type inferred for
Ais[],[any],[any, any], and[number]respectively. Previously, in all but the last example we'd inferany[]forA.