DEV Community

Discussion on: Strongly Typed JSON in TypeScript

Collapse
 
karfau profile image
Christian Bewernitz

I came here expecting an article about having "type safe JSON at runtime", but this is just about JSON data that is already known at compile time.

Collapse
 
nickytonline profile image
Nick Taylor • Edited

Typically what folks do for APIs is generate the types for the different JSON returned.

Here’s an example from Apollo.

And here's another post on how to to do this, stefanwille.com/2021/05/2021-05-30...

Here's another project called restful-react

GitHub logo contiamo / restful-react

A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥

restful-react

npm

⚠️ restful-react will soon be deprecated: We are working on a new open api generator that generates react-query components: github.com/fabien0102/openapi-codegen ⚠️

Building React apps that interact with a RESTful API presents a set of questions, challenges and potential gotchas. This project aims to remove such pitfalls, and provide a pleasant developer experience when crafting such applications.

It can be considered a thin wrapper around the fetch API in the form of React components and hooks.

When used in a setup with OpenAPI / Swagger specs and Typescript, restful-react ensures a reliable and always up to date contract between backend and frontend. It generates components and types from your specs and can be integrated quite comfortably into your development workflows (featuring for example the import of OpenAPI specs from your github repos).

restful-react is very well tested, production ready and powers all of our projects at Contiamo.

And here it is being demoed.

I'm sure there's others.