Skip to content

Adjust copyTypes.js to solve proper schema extension #2

Description

@pjaydev

In the script copyTypes.js, you should replace

...
const modifiedContent = content.replace('@strapi/strapi', '@strapi/types');
...

with

...
const modifiedContent = content.replaceAll('@strapi/strapi', '@strapi/types');
...

otherwise only the first occurance is replaced and the defined ContentTypes interface (defined at the very bottom of the generated contentTypes.d.ts) will still extend @strapi/strapi instead of @strapi/types.

Since we only have a dev dependency on @strapi/types in the frontend app, we won't be able to use proper typing when using the the generated schema types with Strapi's Data namespace, e.g. when referring to known custom entities using the type Data.ContentType<'api::my-collection.my-collection'> as described here in the Strapi docs, since the interface extension is not available when importing the Data class from @strapi/types.

With this adjustmend, I was also successfully able to use the generated types in my Vike frontend app using Strapi v5 in Backend.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions