While working on the new website for Baqend, I noticed that our contentful hooks looked typesafe but when you looked under the hood we had to manually connect the endpoint with the typing for it. This can easily integrate errors into our code. So I took it upon myself to improve that. I started by looking at our old plugin. We used one developed by arimkevi. So I forked this to have a starting ground. I quickly realized that it was written in plain Javascript which I quickly translated to Typescript. It got to a point where I just threw everything away and rewrote everything to fit my need. This leads me to today where this plugin for vite gives you access to an enum containing all the content_ids for contentful.

Together with a generic that matches those endpoints to their extracted type, you can write a function that ensures type safety when calling the contentful API.