Skip to content

Fix assignability of unconstrained T[K] - #23768

Merged
Anders Hejlsberg (ahejlsberg) merged 3 commits into
masterfrom
fixIndexedAccessAssignability
Apr 29, 2018
Merged

Anders Hejlsberg (ahejlsberg) merged 3 commits into
masterfrom
fixIndexedAccessAssignability

Conversation

@ahejlsberg

Copy link
Copy Markdown
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.

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