Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust copyTypes.js to solve proper schema extension #2

Open
pjaydev opened this issue Dec 3, 2024 · 0 comments
Open

Adjust copyTypes.js to solve proper schema extension #2

pjaydev opened this issue Dec 3, 2024 · 0 comments

Comments

@pjaydev
Copy link

pjaydev commented Dec 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant