Skip to content

Union type as argument to overloaded function #11353

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
mchenzero opened this issue Oct 4, 2016 · 1 comment
Closed

Union type as argument to overloaded function #11353

mchenzero opened this issue Oct 4, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@mchenzero
Copy link

TypeScript Version: 2.0.3

Code

function fn(str: string): void;
function fn(num: number): void;
function fn(arg) {
  // do something with arg
}

function test(arg: string | number) {
  fn(arg); // from whatever source I get a (string | number)
}

Expected behavior: This code looks logically valid.

Actual behavior: It results in a compile error: error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. Type 'string' is not assignable to type 'number'.

@RyanCavanaugh
Copy link
Member

Duplicate #1805

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 4, 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

2 participants