I have two types: (() => any) | undefined and () => any. I would like extract the return type of the function but only if the value is definitely not undefined.
I have tried the following:
type IsUndefined<T> = T extends (() => any) ? "no" : "yes";
But this resolves to "yes" | "no" when the type is not undefined. I want to detect the difference between these types without creating a union.
Please see this playground link for an example.
That is the short story, the long story is that I have a struct like the following:
type MyStruct = {
optionalHook?: ((...args: any) => any) | undefined,
requiredHook: (...args: any) => any,
}
I would like to extract the return type of the optional hook, but only when it exists. I would like to extract the return type of the required hook otherwise.
See this playground link for a more comprehensive example.