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

Indexing constraints on mapped type should use the constraint type #12315

Closed
mhegazy opened this issue Nov 16, 2016 · 1 comment
Closed

Indexing constraints on mapped type should use the constraint type #12315

mhegazy opened this issue Nov 16, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Nov 16, 2016

when indexing into a mapped type using a key that is constraint to the same constraint type, indexing should be allowed. consider:

type Optional<T> = {[K in keyof T]?: T[K]}; 

function setFromOther<T, K extends keyof T>(obj: T, k: K, other: Optional<T>) {
    obj[k] = other[k];  // K is not constraint to keyof Optional<T>
}
@ahejlsberg
Copy link
Member

This is fixed by #12351. However, in --strictNullChecks mode the example above still errors because T[K] | undefined is not assignable to T[K], but that's to be expected.

@ahejlsberg ahejlsberg added Bug A bug in TypeScript Fixed A PR has been merged for this issue labels Nov 18, 2016
@ahejlsberg ahejlsberg added this to the TypeScript 2.1.3 milestone Nov 18, 2016
@ahejlsberg ahejlsberg self-assigned this Nov 18, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants