strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Defining Type for relations breaks typescript when creating filters

Open MarijnFK opened this issue 5 months ago • 0 comments

I have the following typescript type:

export type StrapiPage = {
  parent?: Strapi4ResponseSingle<StrapiPage>;
  localizations?: Strapi4ResponseMany<StrapiPage>;
}

Then, when i try to run a find with the following filter to get all pages without a parent.

return {
    parent: {
      slug: {
        $null: true
      }
    }
  };

the following error occurs: Object literal may only specify known properties, and 'slug' does not exist in type 'StrapiPrimitiveOperators | { data?: { id?: StrapiPrimitiveOperators | StrapiNumberOperators | undefined; attributes?: { ...; } | undefined; meta?: { ...; } | undefined; } | undefined; meta?: { ...; } | undefined; }'.

If i write it like this, the error is gone, but ofcourse the filters don't work anymore:

return {
    parent: {
      data: {
          attributes: {
            slug: {
               $null: true
            }
          }
      }
    }
  };

I understand this is because the return value/structure is different from the filter structure, but i'm not sure how to fix this in my StrapiPage type?

MarijnFK avatar Aug 29 '25 06:08 MarijnFK