Say I have a typescript interface:
interface MyInputInterface {
a: A | null
b: B | null
aString: string | null
}
This is what I have currently:
const hasOneNonNull = (input: MyInputInterface) =>
input.a !== null || input.b !== null || input.aString !== null
But this seems very brittle. I have to remember to update the check everytime I add a new interface member. Is there a way to iterate through all the interface members and check that at least one of them is non null?
Something like this would be more ideal (getAllMembers
is pseudocode):
const hasOneNonNull = (input: MyInputInterface) =>
input.getAllMembers().find((elem: any) => any !== null) !== null