Skip to content

Defining Type for relations breaks typescript when creating filters #494

@MarijnFK

Description

@MarijnFK

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions