Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Nov 18, 2016

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).

  • A type S[K] is related to a type T[K] if S is related to T.
  • A type T is related to a type { [P in keyof T]: X } if T[P] is related to X.
  • A type { [P in keyof T]: X } is related to a type T if X is related to T[P].

The PR furthermore adds the following rules:

  • The operation keyof { [P in K]: X } is equivalent to just K. For example, keyof Partial<T> is equivalent to keyof T.
  • The operation { [P in K]: T}[X] is equivalent to an instantiation of T where X is substituted for every occurrence of P. For example, { [P in K]: Box<T[P]> }[X] is equivalent to Box<T[X]>.
  • In type T = { [P in K]: X } it is an error for K to directly or indirectly reference T.
  • Given a type parameter T with a constraint that includes a string index signature of type X, the apparent type of an indexed access type T[K] is X.

Fixes #12311.
Fixes #12315.

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.

4 participants