Skip to content

5.6 regression: Inference related regression: Wider covariant inference gets picked over more narrow contravariant oneΒ #59764

Closed as not planned
@trevorade

Description

@trevorade

πŸ”Ž Search Terms

Inference

πŸ•— Version & Regression Information

  • This changed between versions 5.5.4 and 5.6.0-beta (still happening in 5.6.1-rc)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.1-rc#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChnJgCeADhAFzIDkMmVA3PsuiWMOiHADYAKULAfkoAjTFwhwQjAL65cxMsgDCHAM4BXALbQAPEwD0+5KGbqwyQ8gCqIBOk3bwoAOanzYABbBVyLqBQARDDAAB4QqgGEHijeGhAAdEwAKrgAfMgAvMgAFHBQzpRJAJSZ6QBu6MAAJoy4VRAIXHkoMOq2bBzIqvYQqG0IOikEECGQIFU+GFiWKg4QTiCu6GZR3r7+yEGh4ZGeMapxianZTHYgGtpQlCrnWrpJqQA0TPXw6lxgSYXPRYW19Y1msgzqpzLR0DcLtBrmo7lAdFNUvRkHIQeYoOF3uYst1tH1bNlwZC4Y8cAoKNRwVRpEVGJYCMgAHoCXBAA

πŸ’» Code

interface Foo {
  type: 'foo';
  optionalProp?: boolean;
}

type Consumer<
  // in out // Uncommenting out this line "fixes" the issue.
  T
> = (arg: T) => void;

declare function someFunc<T
  extends Foo // Commenting out this line "fixes" the issue.
>(
  consumer: Consumer<T>,
  defaultT: T,
): T;

declare const fooConsumer: Consumer<Foo>; 

const result = someFunc(fooConsumer, {type: 'foo'});
//    ^?

πŸ™ Actual behavior

result is of type { type: "foo"; }

πŸ™‚ Expected behavior

result is of type Foo as it was in previous releases

Additional information about the issue

See the comments in the example code for two tweaks to make for the code to work as expected. I get adding in out changing things. I'm less clear on why removing the extends should make any difference.

(Google note: relevant source location http://shortn/_eCS9djFiAR)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions