I have created a function.
export default function hasValue(
...params: Array<string | number | object | undefined | null>
) {
return params.every((value) => {
if (value === null || value === undefined) return false;
if (typeof value === "object") return Object.keys(value).length;
return true;
});
}
Now let's say I have created two values that can be undefined.
let a: string | undefined = "a";
let b: number | undefined = 5;
if (hasValue(a, b)) {
//Here a and b still can be undefined as per typescript, but logically, they can't be.
//how can I create a type guard in that function such that a and b won't be undefined in this if block.
}