Skip to content

Instantiating a mapped type does not update the constraint on the type parameter #27596

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

Closed
mattmccutchen opened this issue Oct 7, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript

Comments

@mattmccutchen
Copy link
Contributor

I don't expect real users to write code like this example. I just wanted to get this bug out of the way because I think it will make the solution to #27484 easier to understand.

TypeScript Version: master (85a3475)

Search Terms: mapped type parameter constraint instantiate

Code

type MyMap<T> = {[P in keyof T]: T[keyof T]};
function foo<U>(arg: U): MyMap<U> {
    return arg;
}

Expected behavior: No error.

Actual behavior: Error:

Type 'U' is not assignable to type 'MyMap<U>'.
  Type 'U[P]' is not assignable to type 'U[keyof U]'.
    Type 'P' is not assignable to type 'keyof U'.
      ...

This is nonsense because P in keyof T and we set T = U.

Playground Link: link

Related Issues: none found

mattmccutchen added a commit to mattmccutchen/TypeScript that referenced this issue Oct 7, 2018
This gives the type parameter returned by getTypeParameterFromMappedType
an accurate constraint.

Fixes microsoft#27596.
@mattmccutchen
Copy link
Contributor Author

Fix is #27597.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 9, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.2 milestone Oct 9, 2018
weswigham pushed a commit that referenced this issue Oct 11, 2018
This gives the type parameter returned by getTypeParameterFromMappedType
an accurate constraint.

Fixes #27596.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants