Skip to content

Simplify indexed access types applied to mapped types #28965

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 6 commits into from
Dec 12, 2018

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Dec 11, 2018

Previously we didn't simplify indexed access types applied to mapped types beyond one level because it could cause infinite recursion when mapped types circularly reference themselves. With this PR we now simplify to any number of levels, meaning that constructs such as the following are no longer errors:

function test<T, K extends keyof T>() {
    let x: Partial<Record<keyof T, string>>[K] = "hello";  // Was error, now ok
}

Fixes #28839.

}

function f31<T, K extends keyof T>() {
let x: Partial<Partial<Partial<Partial<Partial<Partial<Partial<Record<keyof T, string>>>>>>>>[K] = "hello";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: Part of me wonders if we should have come rule in place to compact mapped types like this, even when generic.

@ahejlsberg ahejlsberg merged commit fecbdb6 into master Dec 12, 2018
@ahejlsberg ahejlsberg deleted the simplifyIndexedAccess branch December 12, 2018 01:56
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.

2 participants