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

Argument of type 'number' | 'string' is not assignable to overloaded function accepting 'number' or 'string #8350

Closed
osi-oswald opened this issue Apr 28, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@osi-oswald
Copy link

TypeScript Version:

1.8.10

Code

declare function overload(param: number);
declare function overload(param: string);

let bar: number | string;
overload(bar); // Argument of type 'number' | 'string' is not assignable to parameter of type 'string'

Expected behavior:
Since the function 'overload' either accepts a 'number' or a 'string', the compiler should not complain.

Actual behavior:
The compiler complains with: "Argument of type 'number' | 'string' is not assignable to parameter of type 'string'".

Workaround:
Of course I could always rewrite the declaration of 'overload' as:

declare function overload(param: number | string);

But usually these declarations are from external *.d.ts files which I do not want to touch if I don't have to.

@yortus
Copy link
Contributor

yortus commented Apr 28, 2016

Looks like a duplicate of #1805

@osi-oswald
Copy link
Author

You are absolutely right regarding the duplicate

@mhegazy mhegazy closed this as completed Apr 28, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants