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

Bind and Apply calls are not checked against all function overloads #38353

Closed
rkirov opened this issue May 6, 2020 · 2 comments
Closed

Bind and Apply calls are not checked against all function overloads #38353

rkirov opened this issue May 6, 2020 · 2 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@rkirov
Copy link
Contributor

rkirov commented May 6, 2020

TypeScript Version: 3.8.2-dev.201xxxxx

Search Terms: call apply overload

Code

interface Fn {
  (x: string): void;
  (x: number, y: boolean): void;
}

declare const f: Fn;
f(''); // ok
f.call(null, ''); // error 
f.apply(null, ['']); // error

Expected behavior:
No type errors as f('') is equivalent to f.call(null, '') and f.apply(null, ['']).

Actual behavior:
Type errors on f.call(null, '') and f.apply(null, ['']).

Playground Link: Playground Link

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label May 6, 2020
@RyanCavanaugh
Copy link
Member

The call/apply mechanics end up going through the arg-to-tuple process, which isn't capable of handling overloads. Since your return types match, you can write

interface Fn {
  (...args: [string] | [number, boolean]): void;
}

declare const f: Fn;
f(''); // ok
f.call(null, ''); // ok
f.apply(null, ['']); // ok

instead to avoid the error

@rkirov
Copy link
Contributor Author

rkirov commented May 7, 2020

Thanks for explaining, this is not a major issue for us, just wanted to check if it can use a small bug fix, or a known design limitation. Feel free to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants