Skip to content

Fix assignability of unconstrained T[K] #23768

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
Apr 29, 2018

Conversation

ahejlsberg
Copy link
Member

This PR changes the assignability of an unconstrained indexed access to be the same as that of an unconstrained type parameter. Specifically, an unconstrained type parameter is assignable to {} and with this PR the same is true for an unconstrained indexed access.

function foo<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]) {
    let a: {} | null | undefined;
    a = x;  // Ok
    a = y;  // Ok, but was error before this PR
    a = z;  // Ok, but was error before this PR
}

Fixes #21368.
Fixes #23133.

@ahejlsberg ahejlsberg added this to the TypeScript 2.9 milestone Apr 29, 2018
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.

2 participants