Redwood API - Alternative Types Definition Generator

Hi folks, having had a bit of a background in TypeScript - I switched on "strict": true for my redwood app a long time ago and for quite a while accepted that while the types for my app were pretty accurate, they were not always right and often hard to work with:

  • Error messages were very verbose
  • It was hard to describe types where the SDL types and Prisma models did not align perfectly
  • You could not really use those types to pass data between resolvers which wasn’t represented in the SDL

So, over the course of the last few months I had been working on an alternative to the Redwood codegen for the types and this morning I wrapped up all of my issues and 1.0’d it. There’s a long README explaining the full rationale and its feature-set here: GitHub - orta/redwood-codegen-api-types: Replacement types generator for your Redwood API

Getting Set Up

yarn -W add -D @orta/redwood-codegen-api-types

Then to run the codegen locally:

yarn redwood-alt-api-codegen

My recommendation is to add a new "scripts" for "types": "redwood-alt-api-codegen --eslint-fix " - then you can write yarn types and it will do the work. If you’d like to have the in-app types handle for you, I also made an ESLint rule to add the correct types to your resolvers ( here Custom ESLint Rules in Redwood )