Open biggyspender opened 2 years ago
I have same issue too , I also used returnType, however result type always reference a boolean , maybe it's type widening I think about you need to know type widening and type covariant My knowlage is limited ,I can't have a good explanation to you about those
declare function Currying<Fn extends (...args: any) => any>(fn: Fn): ...
const result4 = Currying((a: string, b: number) => 123456)
type A = typeof result4 //result reference number
const result5 = Currying((a: string, b: number) => 'ljsfoe')
type B = typeof result5 //result reference string
they all type widening
You can see extreme Currying2 challenge playground the test type is Boolean
https://github.com/type-challenges/type-challenges/blob/main/questions/00017-hard-currying-1/README.md
If we declare a function:
The return type is widened to be:
Playground Link
So, is it right that the expectation for curried function does NOT expect this widening?
However, this touches on an edge-case in TypeScript where the function may or may not be widened according to the constraints placed on the generic type that represents it.
So, if the generic type is:
the function return type
ReturnType<Fn>
is not widened...however, if the generic type is (which, to my thinking is the preferred solution)
then the function return type
ReturnType<Fn>
is widened toboolean
.See this issue that I opened in SO that better describes the issue.
So, is this expectation correct?
or should it be
?
Compare this solution with this one