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

Type inference is overly strict when dealing w/ Union types and overloads #6503

Closed
nimish opened this issue Jan 15, 2016 · 1 comment
Closed
Labels
Duplicate An existing issue was already created

Comments

@nimish
Copy link

nimish commented Jan 15, 2016

interface OverloadedMethod {
    (a:string): Object;
    (a:number): void;
}

const bar : string|number = 0;
const foo : OverloadedMethod = null;
foo(bar) // red squiggles here under bar: Argument of type 'string | number' is not assignable to 'string'. Type 'string | number' is not assignable to 'number'

This is a minimal example of where typescript complains that bar cannot unify with any of the individual methods on foo, even though it could reasonable deduce that since there's only one implementation of said method, that (a:string|number) : Object|void is a perfectly cromulent alternative.

Looks like this is a consequence of #5766 and it rears it head when dealing w/ Express routing's d.ts.

@nimish nimish changed the title Type inference is leaky when dealing w/ Union types and overloads Type inference is overly strict when dealing w/ Union types and overloads Jan 15, 2016
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 15, 2016
@RyanCavanaugh
Copy link
Member

Please search for duplicates before logging new issues. #1805

@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