Skip to content

Constraints which are generic mapped types should have a constraint of the same mapping over their generic's constraint #21249

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
weswigham opened this issue Jan 18, 2018 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@weswigham
Copy link
Member

weswigham commented Jan 18, 2018

Code

function f<
    T extends { member: string },
    TParam extends Readonly<T>
>(param: TParam, mutableSet: T): TParam {
    const x: string = param.member;
    return param;
}

Expected behavior:
Code works

Actual behavior:
Property member does not exist on type TParam.

When you call f, you must pass a first (and second) argument which provide a member named member (this is enforced), so it's common sense that within f you should always have access to the field of TParam named member. It seems like the issue today is that when calculating a generic's constraint, we don't consider a mapped type's generics' constraints when calculating its constraint.

@jakebailey
Copy link
Member

Just looking at old bugs; this one was fixed all the way back in eeabd52 as part of #26698.

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

4 participants