Closed
Description
TypeScript Version:
1.8.10 (seems, that other are affected as well)
Code
//TYPE DOMAIN
type T1 = (arg: string|number) => string;
type T2 = (arg: string) => string;
declare var fn: T1 | T2;
var res = fn('x'); // error TS2349:
// Cannot invoke an expression
// whose type lacks a call signature.
// VALUE DOMAIN
const f1 = (arg: string|number) => 'x';
const f2 = (arg: string) => 'y';
declare var a: boolean;
const fn1 = a ? f1 : f2
const fn2 = !a ? f2 : f1
var res1 = fn1('x'); // Success, fn1 inferred as (arg: string|number) => string
var res2 = fn2('x'); // Success, fn2 inferred as (arg: string) => string
Expected behavior:
- Code in type domain at least should compile.
- In both domains the correct type for the function should be
(arg: string) => string
and should not be dependent on the order of union members / conditional branches.
Actual behavior:
- Code in type domain fails to compile with error TS2349: Cannot invoke an expression whose type lacks a call signature.
- In value domain the type is dependent on the order of conditional branches