Currently, TypeScript infers generic types when referring its type immediately. Its behavior is undesirable for using higher-order functions. The type inference of generics should delay until it will be called.
functionflip<a,b,c>(f: (a: a,b: b)=>c): (b: b,a: a)=>c{return(b: b,a: a)=>f(a,b);}functionzip<T,U>(x: T,y: U): [T,U]{return[x,y];}varexpected: <T,U>(y: U,x: T)=>[T,U]=flip(zip);varactual: (y: {},x: {})=>[{},{}]=flip(zip);
Currently, TypeScript infers generic types when referring its type immediately. Its behavior is undesirable for using higher-order functions. The type inference of generics should delay until it will be called.