Skip to content

incorrect overload resolution #31368

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
sirian opened this issue May 13, 2019 · 3 comments
Closed

incorrect overload resolution #31368

sirian opened this issue May 13, 2019 · 3 comments

Comments

@sirian
Copy link
Contributor

sirian commented May 13, 2019

I try to resolve all signatures of overloaded functions. It works well except case when one of overloaded signatures has no arguments.

P.S. I know about limitations of conditional types over functions with multiple call signatures.
But this hack widely used to resolve multiple call signatures

TypeScript Version: 3.4.5

Code

type Overloads<F> =
    F extends {
          (...args: infer A1): infer R1
          (...args: infer A2): infer R2;
      } ? {rule: 2, variants: [A1, R1] | [A2, R2]} :
    F extends {
          (...args: infer A1): infer R1;
      } ? {rule: 1, variants: [A1, R1]} :
    never;

declare const ok1: Overloads<(x: number) => boolean>;
// {rule: 1, variants: [[number], boolean]}

declare const ok2: Overloads<{(): 1; (x: number): 2}>;
// {rule: 2, variants: [[], 1] | [[number], 2]}

declare const wrong1: Overloads<() => boolean>;
// {rule: 2, variants: [[], boolean] | [unknown[], {}]}
// expected {rule: 1, variants: [[], boolean]}

declare const wrong2: Overloads<(...args: unknown[]) => boolean>;
// {rule: 2, variants: [unknown[], boolean] | [unknown[], {}]}
// expected {rule: 1, variants: [unknown[], boolean]}
@dragomirtitian
Copy link
Contributor

I think this is a duplicate of #28867

@sirian
Copy link
Contributor Author

sirian commented May 13, 2019

@dragomirtitian Looks like duplicate. But wider: problem not only in no-arg function:

declare const wrong3: Overloads<(x: unknown) => boolean>;
// {rule: 2, variants: [[unknown], boolean] | [unknown[], {}]}
// expected {rule: 1, variants: [[unknown], boolean]}

declare const wrong4: Overloads<(x: any) => boolean>;
// {rule: 2, variants: [[any], boolean] | [unknown[], {}]}
// expected {rule: 1, variants: [[any], boolean]}

@sirian
Copy link
Contributor Author

sirian commented May 13, 2019

I've moved code to #28867. Closing this as duplicate

@sirian sirian closed this as completed May 13, 2019
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

No branches or pull requests

2 participants