When passing a function as a generic type T, the compiler correctly infers the return type when passing a previously declared function, but not when the same function is passed as an inline lambda. This seems to only happens with object literals. Classes and builtin return types are inferred properly.
functionwrapper<T>(fn: T): T{returnfn};varfn=function(x: number){return{ x }};// Correct: type of fnWrapper is (x: number) => { x: number }varfnWrapper=wrapper(fn);// Incorrect: type of inlineWrapper is (x: number) => any varinlineWrapper=wrapper(function(x: number){return{ x }});
When passing a function as a generic type T, the compiler correctly infers the return type when passing a previously declared function, but not when the same function is passed as an inline lambda. This seems to only happens with object literals. Classes and builtin return types are inferred properly.