keyof
should always include remapped keys
#45923
Merged
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.
Fixes #45825
To do this, I've extracted some of the functionality of
resolvemappedTypeMembers
into a common helper and reused it ingetIndexTypeForMappedType
. Doing this correctly necessitates looking at the apparent keys of the inputMappedType
'smodifiersType
if present, which causes new circularity issues in some edge cases involvinginfer
conditionals - to avoid those, we defer expanding thekeyof
in cases where the constraint remains generic, and instead handle membership testing later in relationship checking, with a new relationship rule that can pull the concrete key names out of a target generickeyof MappedType<T>
type. If you have something that is generic (because, eg, it has a homomorphic mapping over the properties of a type with both generic and nongeneric parts), you can still assign to the known bits of the (remapped) key list. In this way a still-generickeyof {[X in keyof (Whatever & T) as Modify<X>]: Stuff}
can behave like aforeach K in (keyof Whatever | Keyof T) -> Modify<K>
on the target side.Eg,
now works, while it did not before.
As a nice side effect of reusing more mapped type member machinery, this discussion is pretty neatly resolved - since the
string
indexer is mapped tonever
, thenumber
type is no longer included.