I am in the process of creating a function that matches React's useState signature:
declare function useState<S>(
initialState: S | (() => S),
): [S, React.Dispatch<React.SetStateAction<S>>];
Below is an excerpt from the function:
function foo<T>(initialState: T | (() => T)) {
typeof initialState === 'function' ? initialState() : initialState;
}
An error message I encounter is:
This expression is not callable.
Not all constituents of type '(() => T) | (T & Function)' are callable.
Type 'T & Function' has no call signatures.(2349)
If T & Function
implies that T
is a function, shouldn't it be callable? How can this issue be resolved without using forced type casts?