Let's say I want to verify that a variable is neither null or undefined.
I would genuinely do:
let foo: string | undefined | null;
if (foo !== undefined && foo !== null) {
// foo is a string
}
Now, I would like to create a function that can do the same check on multiple variable at once.
I have tried:
const isSet = <T>(...values: T[]): values is Exclude<T, null | undefined>[] => {
return values.every(value => value !== undefined && value !== null)
};
However, I get a Typescript error "A type predicate cannot reference a rest parameter", which make sense.
What do you suggest?