Skip to content

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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants