Types are only useful when they agree
A typed frontend can still call an API incorrectly. Handwritten request types tend to begin as accurate copies and slowly become a second, unofficial schema. A renamed field or new nullable state lands in the backend, while the frontend keeps compiling against yesterday’s assumptions.
Generating a TypeScript client from the backend’s OpenAPI document turns the API contract into a build artifact. FastAPI already knows the routes and models; the frontend should consume that knowledge rather than recreate it.
Generation belongs in CI
The useful workflow is repeatable: export the schema, generate the client, format it, and fail when committed output differs. That last step catches drift in the same change that introduced it instead of during integration testing or, worse, at runtime.
Generated code should have a clear boundary. Wrap transport configuration and application-specific behavior outside it so regeneration remains mechanical and reviewable.
set -e
npm run api:schema
npm run api:generate
npm run format
git diff --exit-code -- src/generated/apiLet the contract improve both sides
Client generation exposes vague API design quickly. Inconsistent response shapes, unclear nullability, and anonymous error bodies become awkward types. That friction is useful feedback: improve the contract rather than papering over it in the client.
The payoff is not fewer lines typed. It is one shared definition of the conversation between two systems.