strapi / nextjs-corporate-starter

Strapi Demo application for Corporate Websites using Next.js
MIT License
1.11k stars 353 forks source link

Typescript - Using the 'model.ts' file [ I added a post at the bottom on guide to implement Strapi types in the frontend. #102

Open DimitriPSN opened 1 year ago

DimitriPSN commented 1 year ago

Hi,

I'm looking at the project code and the way you've configured Strapi to see the different options and possibilities offered by the CMS.

I notice that there's a file named 'model.ts' located in 'frontend\src\app[lang]\utils\model.ts'. However, this file is never called up, so the interfaces are never used. Is this intentional or an oversight ?

For example, the file named 'Hero.tsx' located in 'frontend\src\app[lang]\components\Hero.tsx' has a 'Picture' interface, but it could use the one in the 'Model' file.

PaulBratslavsky commented 12 months ago

@DimitriPSN We did not implement Strapi types in this project. Since when this was build we were still making TypeScript enhancements in Strapi.

So the Model.ts file was never used. The issue is that Strapi regenerates its when ever you add new collection types or fields. So in order to get those dynamic types we would need to do more work.

Checkout this article on current TS implementation in your frontend https://strapi.io/blog/improve-your-frontend-experience-with-strapi-types-and-type-script

It show the current work around on how to use Strapi types while we wait to build our SDK.