I have this (simplified version of) function
function empty(value: unknown) {
return value === undefined || value === null;
}
which I’m calling in another function
function foo(user) {
if (empty(user)) return;
console.log(user.id); // error
}
I’m getting a error 'user' is possibly 'undefined'.ts(18048)
error.
How can I make foo (or any other function using empty
) know that the type is safe after checking with empty
. Without using assertions like console.log((user as User).id);