I am working with a generated complex type that is rather big. I need to check if certain properties exists on the type with create a variable and initializing all its properties to default/null values, since that would be too much work.
Is there a way to check if properties exists directly on type without instantiating them or creating a variable with all its properties and checking against it?
ex:
Assuming I have the following
export type Mutations {
upsertItem: {},
upsertItemMany: {},
removeItem: {},
removeItemMany: {},
upsertCustomer: {},
upsertCustomerMany: {},
removeCustomer: {},
removeCustomerMany: {},
... (1000+ more properties exist)
}
I tried to do something like:
var mutations: Mutations;
Object.hasOwn(mutations, 'upsertItem');
But all I get is the following error:
“Cannot convert undefined or null to object”
and if I try to initialize the variable like
let mutations: Mutation = {};
I get an error that I need to specify all its properties which defeats the purpose.
I am guessing this can be solved using reflections but I don’t know how.
buggyCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.