Headline: The most reliable way I have found to keep a Next.js frontend in sync with a NestJS REST API is to treat the OpenAPI spec as the contract: the @nestjs/swagger CLI plugin generates the spec at build time, openapi-typescript turns it into TypeScript types, and openapi-fetch makes every call type-checked. A CI step that regenerates both files and runs git diff --exit-code turns an unannounced contract change into a failed build instead of a production bug.
For a long time my Next.js apps talked to NestJS backends through types I copied by hand, or at best through a shared types package in the monorepo. Both drifted. A renamed field compiled fine on the frontend and rendered undefined in production.…