AI's TypeScript Best Practices for Frontend-Backend Integration: What Are We Missing?
I've used TypeScript for so long, yet I've never quite mastered it. Where does the problem lie? Let's look at the best practices AI wrote and see what our projects are missing.

I wonder if others have the same experience: I've used TypeScript for ages and still can't seem to get the hang of it.
- If I want to do it well, it takes a huge amount of time and energy, writing types one by one against the backend API docs.
- If I want to cut corners, I write a few
anys, bugs show up, and they're hard to deal with.
And it's not just ordinary developers who suffer from this; even experts can't avoid it. There have been reports of well-known developers giving up on TypeScript in their projects.
After I started coding with AI, though, I resolutely chose TypeScript to prevent AI from making basic mistakes. While debugging, I can see the errors AI writes, and the latest models can even correct themselves based on those errors. It is indeed much more convenient.
Since TypeScript is still necessary, why not ask AI for best practices and see if it can help us break through the limits we hit before?
No time like the present: with just a few words, AI listed several approaches currently available.
1. Overview of the Approaches
At present there are four approaches. AI helpfully explained how to choose among them for different project scenarios.
| Scenario | Recommended approach |
|---|---|
| Traditional REST API | OpenAPI + automatic generation |
| GraphQL architecture | GraphQL Codegen |
| Flexible APIs / no documentation | Zod runtime validation |
| Full-stack TypeScript | tRPC (alternative) |
For the full-stack tRPC approach, you can check out the official website: Node.js tRPC official website.
Below is the specific code AI provided for approaches 1 through 3.
2. The Approaches in Detail

Approach 1 is relatively easy to understand: use a tool to read swagger.json and directly output a type file plus a set of request functions.
The advantages are obvious: fully automated synchronization, so backend changes automatically update frontend types.
The downside is the prerequisite: the backend must follow conventions and write good code for Swagger to output correctly. This approach also generates a wrapped axios client that takes some effort to understand and is a bit of a hassle to modify.
Approach 2 is similar. For a GraphQL setup, there are also code generators; once the relevant documentation is configured, they can output type files too.
A GraphQL architecture reduces the workload of developing CRUD endpoints to some extent and connects the database with frontend and backend work. So this approach is better than approach 1, but it only applies to projects that use GraphQL.

Approach 3 is probably the one that suits most projects. Its advantage is runtime validation as a safety net, preventing type deception.
One benefit of the Zod library is that it saves a lot of time writing validation methods.
But the downside is all too obvious: the frontend still has to write a lot of code to implement it.
Summary
In theory, both traditional REST APIs and newer GraphQL architectures have tools that can automatically generate type files, so the frontend can basically just call the generated code.
But in practice, things often don't work out that way.
- With traditional REST APIs, many projects are probably legacy systems, and their Swagger support is so-so. Rewriting the Swagger spec would undoubtedly add to the backend team's workload.
- As for GraphQL architectures, of those I've worked with or seen, almost no company in China uses them.
- As for approach four, tRPC, both the frontend and backend need to be implemented in Node, and few companies in China do that today.
All things considered, putting these into practice is still difficult.
The only truly practical option is the frontend developer's manual approach to writing types. If you still have room to make changes, try using Zod to reduce some of the work.
Takeaways
This also gave me some food for thought:
- Someone always has to do the work. If you don't do it, someone else will; if they don't, it comes back to you. Work doesn't disappear into thin air.
- The earlier a standardized process is implemented, the better. Push through every obstacle to implement it; the payoff will ultimately be worth it.
The second point is something I've been thinking about for a long time: rigorous adherence to standardization is exactly what we're missing.
While our frontend teams are still arguing about whether to configure ESLint, and our backend teams are still arguing about whether to follow RESTful APIs, others may have already integrated the entire workflow and built out the surrounding ecosystem. Often, the fastest and least effortful path is to skip the debate and just use a standard solution.
So when people abroad turned to AI, everything ran incredibly fast because it was all standardized. We are developing too, but it always feels like we're following in others' footsteps.
This even extends to enterprise IT. Companies always say they have their own processes, so they end up creating all sorts of strange projects and subprojects. As the company grows, these become more and more complicated and redundant, until change becomes increasingly difficult.
What do you think about this?
Feel free to leave your footprints in the comments.