Settings

Theme

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

github.com

1 points by gladwindos 2 years ago · 6 comments · 1 min read

Reader

Hi 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!

alpy 2 years ago

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

  • gladwindosOP 2 years ago

    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.

beeman 2 years ago

Is there any benefit over using this versus an industry standard like OpenAPI/Swagger?

Does it add any new features?

  • gladwindosOP 2 years ago

    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.

    • beeman 2 years ago

      Got it, that makes sense.

      Maybe good to describe that use case in the README.

      • gladwindosOP 2 years ago

        Yeah I think that’s a good idea as a few people have thought the same thing. Thanks for the feedback!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection