One approach to using TypeScript with GraphQL is to generate a TypeScript type library based on a GraphQL schema, creating interfaces for all of the objects we might use in the code, which does work fine.

However, there is a safer way to do this, and that is by having unique types for every situation, rather than shared types that can be used everywhere. In this article, I’ll explain what’s wrong with this approach as well as a mechanism on how to improve it.