Higher order type relations for mapped types#12351
Merged
Uh oh!
There was an error while loading. Please reload this page.
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 adds a number of type relations for higher order mapped types and indexed access types (i.e. un-instantiated generic forms of the types).
S[K]is related to a typeT[K]ifSis related toT.Tis related to a type{[P in keyof T]: X }ifT[P]is related toX.{[P in keyof T]: X }is related to a typeTifXis related toT[P].The PR furthermore adds the following rules:
keyof{[P in K]: X }is equivalent to justK. For example,keyof Partial<T>is equivalent tokeyof T.{[P in K]: T}[X]is equivalent to an instantiation ofTwhereXis substituted for every occurrence ofP. For example,{[P in K]: Box<T[P]>}[X]is equivalent toBox<T[X]>.type T ={[P in K]: X }it is an error forKto directly or indirectly referenceT.Twith a constraint that includes a string index signature of typeX, the apparent type of an indexed access typeT[K]isX.Fixes#12311.
Fixes#12315.