I have the types as follows:
type Operators =
| "eq"
| "ne"
| "lt"
| "gt"
| "lte"
| "gte"
| "in"
| "nin"
| "contains"
| "ncontains"
| "containss"
| "ncontainss"
| "between"
| "nbetween"
| "null"
| "nnull"
| "or"
type Filter = {
field: string;
operator: Operators;
value: any
};
export type Filters = Filter[];
What I am trying to do is define the Filter type by the Operators type.
If the user specifies Operators as "or" then the field property is not required and the value property is Filters type. As follows:
export type Filter = {
field: string | undefined;
operator: Operators;
value: Filters;
};
If the user specifies Operators other than "or" then the field property is required and the value property is any type. As follows:
export type Filter = {
field: string;
operator: Operators;
value: any
};
How can I determine the type of another property of same object according to the property's value of the object?