Skip to content

Inferences from type aliases disregard variance #31659

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

Closed
ahejlsberg opened this issue May 29, 2019 · 3 comments · Fixed by #31662
Closed

Inferences from type aliases disregard variance #31659

ahejlsberg opened this issue May 29, 2019 · 3 comments · Fixed by #31662
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ahejlsberg
Copy link
Member

ahejlsberg commented May 29, 2019

TypeScript Version: 3.5.0 and previous

Code

// @strictFunctionTypes: true

type Func<T> = (x: T) => void;

declare let f1: Func<string>;
declare let f2: Func<"a">;

declare function foo<T>(f1: Func<T>, f2: Func<T>): void;

foo(f1, f2);  // Error

Expected behavior:

No error.

Actual behavior:

Error.

When inferring between instantiations of the same type alias we always make covariant inferences instead of computing and using proper variance information.

@ahejlsberg ahejlsberg self-assigned this May 29, 2019
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label May 29, 2019
@ahejlsberg ahejlsberg added this to the TypeScript 3.6.0 milestone May 29, 2019
@jcalz
Copy link
Contributor

jcalz commented May 29, 2019

Possibly duplicate of or related to #31251 and #31295?

@ahejlsberg
Copy link
Member Author

Possibly duplicate of or related to #31251 and #31295?

No, I don't think either of those are related.

@jcalz
Copy link
Contributor

jcalz commented May 29, 2019

Okay (@jcalz slinks away)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants