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

Different type-inference with two structurally identical types #48116

Open
hreinhardt opened this issue Mar 4, 2022 · 1 comment
Open

Different type-inference with two structurally identical types #48116

hreinhardt opened this issue Mar 4, 2022 · 1 comment
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@hreinhardt
Copy link

Bug Report

πŸ”Ž Search Terms

inference identical

πŸ•— Version & Regression Information

3.5-3.9, 4.0-4.6, 4.7.0-dev.20220304 (did not test earlier versions)

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Identity<A> =
      A extends object
    ? {[K in keyof A]: Identity<A[K]>}
    : A;

type HasValue1<A> = {
    value:Identity<A>;
}
type HasValue2<A> = {
    value:Identity<A>;
}

function test<B>(a:HasValue1<B>) {}

function foo1<A>(a:HasValue1<A[]>) {test(a)} // OK
function foo2<A>(a:HasValue2<A[]>) {test(a)} // type-error

πŸ™ Actual behavior

The body of foo2 does not type-check because the wrong type for type-variable B is inferred.

πŸ™‚ Expected behavior

The body of foo2 should type-check exactly as foo1 since HasValue1 and HasValue2 are structurally the same type.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 4, 2022
@RyanCavanaugh
Copy link
Member

@ahejlsberg I heard you like variance issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants