Skip to content

Properly handle co- and contra-variant inferences in strict mode #26566

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 5 commits into from
Aug 21, 2018

Conversation

ahejlsberg
Copy link
Member

Fixes #26127.

>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
>"abc" : "abc"
>fo : (x: Object) => void
>fs : (x: string) => void

const x3 = f3("abc", fo, fx); // "abc" | "def"
>x3 : Object
>f3("abc", fo, fx) : Object
>x3 : "def" | "abc"
Copy link
Member

Choose a reason for hiding this comment

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

We should discuss this later, but this inference seems bad

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this inference is correct. The fx argument is a function taking a function, and since contra-contra-variant is the same as co-variant, we make two co-variant inferences, "abc" and "def". Per normal rules we union together literal inferences for the same type parameter, so we end up with "abc" | "def".

Copy link
Member

Choose a reason for hiding this comment

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

Missed the double 180; you're right

@ahejlsberg ahejlsberg merged commit 7ec98af into master Aug 21, 2018
@ahejlsberg ahejlsberg deleted the fixStrictCoAndContraInferences branch August 21, 2018 23:11
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