You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
This is a minimal example of where typescript complains that
bar
cannot unify with any of the individual methods onfoo
, 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.
The text was updated successfully, but these errors were encountered: