In our open source library @thisisagile/easy. We have defined a type Get<T = unknown, Args = unknown> = T | Func<T, Args>
(see Get
), which is either a function or an object, and a function ofGet<T>()
that evaluates it.
In some edge cases, however, when we define a get from a function that returns an any
, the behavior is different than what you would expect. I imagine this has to do with that the compiler can't see the difference and chooses the evaluate the use of the type as any
instead of () => any
.
So, I'm wondering if we could define a conditional type where we could exclude any
, e.g. Get<T, Args> = IsAnAny<T> ? Func<T, Args> : (Func<T, Args> | T)
. Any ideas?