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

Add assignability rule relaxing the assignability of partial mapped types #30112

Merged
merged 2 commits into from
Mar 8, 2019

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Feb 27, 2019

Fixes #30081

The usual rule right now is that all the keys in the target mapped type's constraint must be assignable to the source's keys. With this change, for partial mapped types, only some key of the partial mapped type must be assignable to the source's keys (and then only with those keys do we index into the source to compare values).

const hasOptionalUnionKeys = modifiers & MappedTypeModifiers.IncludeOptional && targetConstraint.flags & TypeFlags.Union;
const filteredByApplicability = hasOptionalUnionKeys ? filterType(targetConstraint, t => !!isRelatedTo(t, sourceKeys)) : undefined;
// A source type T is related to a target type { [P in Q]: X } if Q is related to keyof T and T[Q] is related to X.
// A source type T is related to a target type { [P in Q]?: X } if some Q = Q' is related to keyof T and T[Q'] is related to X.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// A source type T is related to a target type { [P in Q]?: X } if some Q = Q' is related to keyof T and T[Q'] is related to X.
// A source type T is related to a target type { [P in Q]?: X } if some constituent Q' of Q is related to keyof T and T[Q'] is related to X.

@weswigham weswigham merged commit 58e847a into microsoft:master Mar 8, 2019
@weswigham weswigham deleted the mapped-type-constraint branch March 8, 2019 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants