Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Higher order type relations for mapped types#12351

Merged
ahejlsberg merged 6 commits into
mastermicrosoft/TypeScript:masterfrom
mappedTypeRelationsmicrosoft/TypeScript:mappedTypeRelationsCopy head branch name to clipboard
Nov 18, 2016
Merged

Higher order type relations for mapped types#12351
ahejlsberg merged 6 commits into
mastermicrosoft/TypeScript:masterfrom
mappedTypeRelationsmicrosoft/TypeScript:mappedTypeRelationsCopy head branch name to clipboard

Conversation

@ahejlsberg

@ahejlsberg ahejlsberg commented Nov 18, 2016

Copy link
Copy Markdown
Member

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.