I am working with a Typescript library authored by someone else. In one of the functions, it takes a parameter that can be a function or a value like:
function returnDefault<T>(defaultVal: T | () => T): T {
if(typeof defaultVal === 'function') {
return defaultVal();
}
return defaultVal;
}
When attempting to use this function, I am getting a Typescript error "This expression is not callable. Not all constituents of type '(() => T) | (T & Function)' are callable. Type 'T & Function' has no call signatures." This error appears on the third line (return defaultVal();). What am I doing wrong here or how can I fix this error?