I've recently encountered a production bug due to using `any` in my code, and it made me rethink how I handle external data. I'm curious, how do you approach specifying and validating API response types in your projects? Any tools or strategies that work well for you?
5 Answers
I've found using OpenAPI generated types to be pretty handy. But if you want to go the hard way, GraphQL is also an option! Just remember, both come with their frustrations. 😂
Don’t forget about oRPC if you want a smoother experience!
Consider using Zod or similar libraries for validating your data. It helps ensure what you're receiving is actually what you expect. It can save you from a lot of headaches down the line!
Using OpenAPI to drive your types or even some SDK generation tools can save you some serious time. Just keep in mind that the real world often throws messy APIs your way, and generated types can sometimes be misleading if the specs aren’t up to date. It’s a balance! So, use these tools wisely!
Absolutely! The ideal is clean, structured APIs, but in reality, that’s just not always the case.
If you’re getting into types, Kiota can be an option for newer projects. It’s not perfect, but it can really help with managing types effectively. And hey, always better to fix the typing at the source than dealing with unknowns later!
Honestly, just don’t use "any". It's such a lazy approach that can lead to messy code! Trust me; you’ll be better off sticking to stricter typings.
Right? Even using Postman to check what your API returns is going to give you a clearer picture than relying on `any`.

True, OpenAPI can definitely have its challenges too! It’s a love-hate thing.