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

union-proof the 'generic mapped type' check #18036

Conversation

KiaraGrouwstra
Copy link
Contributor

@KiaraGrouwstra KiaraGrouwstra commented Aug 25, 2017

Fixes #15756.

This incidentally also uncovered one other case (Form from keyofAndIndexedAccess) where generic mapped types had been applied in an unsound way w.r.t. union keys. That simplified heuristic worked there for the basic case of non-union types, but without it inference ended up no longer strong enough there.
That appears a piece of collateral damage here, though I'm under the impression the altered check here wasn't wrong about such reduction being unsound there.

To elaborate:

class Form<T> {
    private childFormFactories: {[K in keyof T]: (v: T[K]) => Form<T[K]>}

    public set<K extends keyof T>(prop: K, value: T[K]) {
        this.childFormFactories[prop](value)
    }
}

Reduction makes for {[K in keyof T]: (v: T[K]) => Form<T[K]>}[K] -> (v: T[K]) => Form<T[K]>. If one substitutes some union A|B for K, that makes for (v: T[A|B]) => Form<T[A|B]>, distinct from the (I believe) expected result here of ((v: T[A]) => Form<T[A]>) | ((v: T[B]) => Form<T[B]>). That's why I believe this reduction here was technically unsound even though it would have held for the base case of non-unions.

This incidentally also uncovered one other case where generic mapped types had been applied in an unsound way w.r.t. union keys.
@msftclas
Copy link

@tycho01,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@gcnew
Copy link
Contributor

gcnew commented Aug 25, 2017

I like your approach very much! Both the union test and the use of a synthetic generic function. 👍

@KiaraGrouwstra
Copy link
Contributor Author

KiaraGrouwstra commented Aug 25, 2017

@gcnew thanks! wish I had a better idea on some of the other issues as well 😅, for the most part I'm just opening PRs before even knowing what I'm doing yet haha

@KiaraGrouwstra
Copy link
Contributor Author

Closing, fixed by #18042!

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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.

3 participants