Skip to content

A function overload that is mistakenly unassignable to an intersection type. #57112

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
craigphicks opened this issue Jan 21, 2024 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@craigphicks
Copy link

craigphicks commented Jan 21, 2024

πŸ”Ž Search Terms

#57087

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried (from 3.3.3~)
    • In versions before satisfies was implemented, had to test with extends - same result.

⏯ Playground Link

No response

πŸ’» Code

interface C {
  (x:1):"1";
  (x:2):"20";
  (x:number):number;
}
interface B {
  (x:2):"2"
  (x:3):"30"
  (x:number):number;
}
interface A {
  (x:3):"3"
  (x:1):"10"
  (x:number):number;
}

function foo(x:1):"1";
function foo(x:2):"2";
function foo(x:3):"3";
function foo(x:number):number|"1"|"2"|"3"{
  if (x==1||x==2||x==3) return String(x) as any;
  return x;
}

// The `&`-intersection operator result should be independent of the order of it's operands.
foo satisfies A & B & C; // error (incorrect)
foo satisfies A & C & B; // error (incorrect)
foo satisfies B & A & C; // error (incorrect)
foo satisfies B & C & A; // error (incorrect)
foo satisfies C & A & B; // error (incorrect)
foo satisfies C & B & A; // error (incorrect)

// W stands for (attempted) "W"orkaround
type W = (A & B & C)|(A & C & B)|(B & A & C)|(B & C & A)|(C & A & B)|(C & B & A);
declare const w:W;
w(1);// "1","10"
w(2);// "2","20"
w(3);// "3","30"

foo(1); // "1"
foo(2); // "2"
foo(3); // "3"

// So the following should pass.
foo satisfies W; // error (incorrect)
//  ~~~~~~~~~
// Type '{ (x: 1): "1"; (x: 2): "2"; (x: 3): "3"; }' does not satisfy the expected type 'W'.
//  Type '{ (x: 1): "1"; (x: 2): "2"; (x: 3): "3"; }' is not assignable to type 'A & B & C'.(1360)

πŸ™ Actual behavior

Every satisifies statement is failing.

πŸ™‚ Expected behavior

Every satisifies statement should pass.

Additional information about the issue

Proposal #57087 should fix it.

@RyanCavanaugh
Copy link
Member

Proposal #57087 should fix it.

πŸ‘

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 22, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
3 participants