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

Higher order type relations for mapped types #12351

Merged
merged 6 commits into from
Nov 18, 2016
Merged

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.

3 participants