#✅ How to resolve Typescript issue when using readByQuery() on user_created?

1 messages · Page 1 of 1 (latest)

flint rock
#

Object literal may only specify known properties, and 'user_created' does not exist in type 'QueryMany<PersonalInfo>'

I'm using the Directus JS-SDK and have set up my schemas to be read in when I retrieve the directus client

type PersonalInfo {
    firstName: string
    lastName: string
    // user_created: string
}

type Schemas = {
    personal_info: PersonalInfo
}

export const getDirectusClient = async () => {
    const directus = new Directus<Schemas>(
        import.meta.env.PUBLIC_DIRECTUS_URL as string,
    )
}

Then on my page I make a request to query the collection PersonalInfo filtered by the logged-in user

const directus = await getDirectusClient()

export const user = await directus.users.me.read()

export async function getPersonalInfo() {
    const { data } = await directus
        .items('personal_info')
        .readByQuery({ user_created: user.id })

    return data ? data[0] : data
}

This works, but typescript complains about it with the message I posted up top. Any advice how to make the red squiggle go away?

visual pulsarBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

flint rock
#

using the filter object solved it for me

export async function getPersonalInfo() {
    const { data } = await directus.items('personal_info').readByQuery({
        filter: {
            user_created: {
                _eq: user.id,
            },
        },
    })

    return data ? data[0] : data
}
visual pulsarBOT
#

✅ How to resolve Typescript issue when using readByQuery() on user_created?