Surely been asked before but I can't find the right search terms atm...
Why does this:
function nextItem<T>(item: T | (() => T)) {
const next = typeof item == "function" ? item() : item;
}
Give me this error:
This expression is not callable.
Not all constituents of type '(() => T) | (T & Function)' are callable.
Type 'T & Function' has no call signatures.(2349)
This is one of those things that I'm both sure TS has a good reason to work this way, but I have no idea why. How could it not be a callable function right of the type guard?
I also noticed this does narrow the type and avoid the type error:
function nextItem2<T>(item: T | (() => T)) {
const next = "call" in item ? item() : item;
}
But that does not seem right at all.
