Closed as not planned
Description
π Search Terms
5.8, return, type
π Version & Regression Information
- This changed between versions 5.7.3 and 5.8.2
β― Playground Link
No response
π» Code
export type ReturnTypeOrStatic<T> = T extends (...args: any[]) => infer R ? R
: T;
export function evalOrStatic<T>(
fnOrConst: T,
...args: any[]
): ReturnTypeOrStatic<T> {
return typeof fnOrConst === "function" ? fnOrConst(...args) : fnOrConst;
}
π Actual behavior
Error under fnOrConst
at the end of the conditional:
Type 'T' is not assignable to type 'ReturnTypeOrStatic<T>'
π Expected behavior
no error. If fnOrConst
is a function, its return value (type R
) is returned, otherwise it is returned directly (type T
).
Additional information about the issue
No response