Skip to content

Incorrect inferred return type when returning object literal from lambda bound to generic parameter #5487

Description

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 }});

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions