Show HN: API Typegen – Generate TypeScript types from API responses
github.comHi all,
I’ve been working on a node.js package that generates typescript types from API responses. I would love to know what you think and would appreciate any feedback! It would be interesting to know how it works for you in a real project. I often have to create types for undocumented endpoints, but it's always a guessing game. Without a proper spec or reading the source code, it's impossible to know if a field is nullable or not, or to distinguish a real text field from a string based enum Yeah I agree that it is impossible to know exactly what the fields are without a real documented source, but I figured this could be a decent option when there are no other alternatives available. While it's not perfect, it can provide a starting point for creating types based on sample data, which can then be refined as you work with the API and gain more understanding. Is there any benefit over using this versus an industry standard like OpenAPI/Swagger? Does it add any new features? Tbh, there is no benefit of using this package if the API you are working with has an openapi spec, as there are other great libraries to help you generate accurate types such as https://github.com/openapi-ts/openapi-typescript. But I made this package to use when working with external apis that don't have an available spec. Got it, that makes sense. Maybe good to describe that use case in the README. Yeah I think that’s a good idea as a few people have thought the same thing. Thanks for the feedback!