Skip to content

Populate Dynamic Zones type error #505

@DmtrRvk

Description

@DmtrRvk

If I define "populate" for dynamic zones in Strapi as specified on the Strapi Docs page.
Then the type check fails and highlighted in IDE because the "on" definition is not allowed according to Strapi5RequestPopulateParam type.

Version

@nuxtjs/strapi: 2.1.1
nuxt: 4.2.2
Strapi: v5

Steps to reproduce

Create a types, like this:

type TStrapiContentEntry = {
  id: number;
  documentId: string;
};

type TStrapiImage = TStrapiContentEntry & {
  name: string;
  url: string;
  alternativeText: string;
  formats: {
    thumbnail: {
      url: string;
    };
    small?: {
      url: string;
    };
    medium?: {
      url: string;
    };
    large?: {
      url: string;
    };
  };
};


type TSectionHero = TStrapiComponent & {
  __component: 'sections.hero';
  heading: string;
  image: TStrapiImage;
};

export type TSectionGallery = TStrapiComponent & {
  __component: 'sections.gallery';
  heading: string;
  images: TStrapiImage[];
};

type TSection =
  | TSectionHero
  | TSectionGallery;

type TSections = TSection[];

type TPage = TStrapiContentEntry & {
  title: string;
  sections: TSections;
};

then add this script:

const { find } = useStrapi();
const { data } = await find<TPage>('pages', {
      populate: {
        sections: {
          on: {
            'sections.hero': {
              populate: ['image'],
            },
            'sections.gallery': {
              populate: ['images'],
            },
          },
        },
      },
      pagination: {
        page: 1,
        pageSize: 1,
      },
    });

What is Expected?

There should be no warning in IDE (WebStorm).

What is actually happening?

I get the following warning in IDE:

Type sections is not assignable to type Strapi5RequestPopulateParam | undefined
Types of property sections are incompatible.
Object literal may only specify known properties, and on does not exist in type

However code works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions