Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typed "where" queries in Local API #9685

bhofstaetter announced in Roadmap
Discussion options

Hi, I want to make local api calls partly reusable in a function. To make this work properly I want to type "Where". How can I achieve this?

import {BasePayload, Where} from 'payload';
export const countUsers = async (where: Where, payload: BasePayload): Promise<number> =>
 payload
 .count({
 collection: 'users',
 where,
 })
 .then((result) => result.totalDocs);
You must be logged in to vote

Replies: 2 comments

Comment options

Unfortunately, the where property is not strongly typed. You can use import { Where } from 'payload', as you have in your code snippet but that will only add the "and" and "or" properties. I guess this requires improvement.

You must be logged in to vote
0 replies
Comment options

I've just started using Payload, coming across from Keystone. Really happy and impressed with it so far but quite surprised to run into this issue where there is no typing on where. Hoping this feature gets incorporated soon 🙏🏼

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /