After extensive work, I've managed to develop a function that fulfills the vital runtime requirement of checking for null and undefined not being true:
function checkFieldsExistence<T>(obj: T | T[], ...fields: (keyof T)[]): boolean {
const inObj: { (obj: T): boolean } = (obj) => fields.every((f) => obj[f] != null);
if (Array.isArray(obj)) {
return obj.every((o) => inObj(o));
} else {
return inObj(obj);
}
}
However, my ultimate goal is to create a functionality that can either update an object with a new type, or allow me to leverage this within an if statement and have the types updated dynamically within the context of the if statement.
I've come across similar queries like this one on StackOverflow: Typescript type RequireSome<T, K extends keyof T> removing undefined AND null from properties, but it doesn't quite cater to a list of fields as required.
For reference, the fields in question are known during compile time.