Live data from Hacker News

Show HN: API Typegen – Generate TypeScript types from API responses

github.com

1–7 of 7 posts

Re: Show HN: API Typegen – Generate TypeScript types from API responses

#3
post #2

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.

Re: Show HN: API Typegen – Generate TypeScript types from API responses

#4
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

Re: Show HN: API Typegen – Generate TypeScript types from API responses

#5
post #2

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.

Re: Show HN: API Typegen – Generate TypeScript types from API responses

#6
post #5

Earlier quoted context omitted.

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!

Re: Show HN: API Typegen – Generate TypeScript types from API responses

#7
post #4

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.