Skip to content

No constraint for { [P in K]: XXX } where K is type variable #28170

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

Merged
merged 3 commits into from
Oct 26, 2018

Conversation

ahejlsberg
Copy link
Member

The following currently produces no errors:

function test1<T, K extends keyof T>(obj: Pick<T, K>) {
    let x = obj.foo;
    let y = obj.sayWhat;
}

function test2<T, K extends keyof T>(obj: Record<K, number>) {
    let x = obj.foo;
    let y = obj.sayWhat;
}

That's obviously not right. This PR removes the code that gets this wrong in resolveMappedTypeMembers.

@ahejlsberg
Copy link
Member Author

@typescript-bot test this.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 26, 2018

Heya @ahejlsberg, I've started to run the extended test suite on this PR at 30d1ecd. You can monitor the build here. It should now contribute to this PR's status checks.

@ahejlsberg
Copy link
Member Author

ahejlsberg commented Oct 26, 2018

Looked over the RWC baseline changes. There are new errors in one project, all of which are correct and relate to uses of Pick<T, K> that are strange (e.g. functions with a type parameter K that is never used in the parameter list).

@ahejlsberg ahejlsberg merged commit ccc1613 into master Oct 26, 2018
@ahejlsberg ahejlsberg deleted the fixGenericMappedTypeConstraint branch October 26, 2018 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants