-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Expand the tuple contextual type to the target's shape when it comes from a binding pattern #52630
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
Conversation
src/compiler/checker.ts
Outdated
// this allows us to infer tuples even if the binding pattern is shorter than the target type, like here: | ||
// declare function fn<T>(t: T) => [T, string[]]; | ||
// const [[x]] = fn(['hi']); | ||
else if (isTupleType(contextualType) && isTupleType(inferenceTargetType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't handle the case when inferenceTargetType
is a union of tuple types but I have no idea how "expansion" towards that shape should work - unless all union members would have the very same shape
…from a binding pattern
This seems pretty reasonable to me. @typescript-bot user test this |
Heya @andrewbranch, I've started to run the diff-based top-repos suite on this PR at cfc350b. You can monitor the build here. Update: The results are in! |
Heya @andrewbranch, I've started to run the diff-based user code test suite on this PR at cfc350b. You can monitor the build here. Update: The results are in! |
Heya @andrewbranch, I've started to run the perf test suite on this PR at cfc350b. You can monitor the build here. Update: The results are in! |
@andrewbranch Here are the results of running the user test suite comparing Everything looks good! |
@andrewbranch Here are the results of running the top-repos suite comparing Everything looks good! |
@andrewbranch Here they are:
CompilerComparison Report - main..52630
System
Hosts
Scenarios
TSServerComparison Report - main..52630
System
Hosts
Scenarios
StartupComparison Report - main..52630
System
Hosts
Scenarios
Developer Information: |
# Conflicts: # tests/baselines/reference/inferTupleFromBindingPattern.js # tests/baselines/reference/inferTupleFromBindingPattern.symbols # tests/baselines/reference/inferTupleFromBindingPattern.types
resultFlags = source.target.elementFlags.slice(); | ||
} | ||
const targetFlag = target.target.elementFlags[i]; | ||
resultTypes.push(anyType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than any
with the target flags, shouldn't it be never
with the optional flag? To reflect how the consumer never reads the member?
This gets superseded by #56875 since this PR here aimed to solve the problem through special-casing and the new PR takes a much more general approach to this and similar problems. |
fixes #42969
cc @andrewbranch