Where
type is defined as
type Where = {
[key: string]: WhereField | Where[];
or?: Where[];
and?: Where[];
}
What does it mean if a key has a value of Where[]?
e.g.
{
"hero": [{
"type" : { "equals": "basic"}
}]
}
is that the same as
{
"hero.type": { "equals": "basic"}
}
Or does it mean something else? And if so, what?
You need to use the dot notation version
Yes, I know. But I'm trying to create a type safe query builder for my payload-rbac library, so I'm trying to understand the type definition. the type definition specifies that I can use
{ [key: string}: Where[] }
.What does this mean?
If this is just to satisfy the type system to support the
or
and
and
property, then I can ignore it. But if it has some meaning, than I can't.
Got it. Yes it is just for and/or
This is what I've got so far:
import { WhereField } from 'payload/types';
type ValueOf<T extends object> = T[keyof T];
type AllKeys<T> = T extends object ? (keyof T & string) | ValueOf<{ [K in keyof T & string]: `${K}.${AllKeys<T[K]>}` }> : never;
export type Where<T extends object = any> = Record<AllKeys<T>, WhereField> & {
or?: Where<T>[];
and?: Where<T>[];
};
But that doesn't take the
[key: string]: Where[]
into account.
Thanks
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.