hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.44k stars 105 forks source link

Export Options object types #38

Closed Darhagonable closed 9 months ago

Darhagonable commented 9 months ago

PR refactor(types): generate types for services when useOptions is true added types of the Options objects. Would be nice if these were exported as well

mrlubos commented 9 months ago

You can access them via Parameters<typeof MyService.operationName>[0] I believe, does that work for you?

Darhagonable commented 9 months ago

Thats what im currently doing. It works but is more verbose. Exporting those types would be a nice to have though :P

mrlubos commented 9 months ago

@Darhagonable Done! For now I literally export the types that were there, maybe in the future it would make more sense to organise them into a separate types folder

Darhagonable commented 7 months ago

@mrlubos types like this no longer seem to be exported or am i missing some migration step at some point?

mrlubos commented 7 months ago

Are you able to import $OpenApiTs from types.gen? Just be warned this API isn't finalised yet and may change. I personally tend to use service classes to get to response or payload types - ReturnType<typeof DefaultService.foo>

Darhagonable commented 7 months ago

@mrlubos Yes i can import $OpenApiTs. So if I'm understanding correctly TDataGetApiV1Foo has been changed to $OpenApiTs["/api/v1/foo"]["get"]["req"]? Should probably be added to the migrations docs.

Seems then that the verbose ReturnType useage is the preferred option indeed.

mrlubos commented 7 months ago

That sounds right. Honestly, you might be the only person using those types right now, since in the past you couldn't get to them in any other way than ReturnType<typeof DefaultService.foo> which is why I started using that. Of course, there might be times when you don't want to pull in the service import to your file. We could make the types exported too as you wrote above, but the more you export the more likelihood there will be a naming conflict, and we currently don't have a good way to detect and correct those. Also, this tree structure is a setup for https://github.com/hey-api/openapi-ts/issues/28. Once that is resolved, maybe we can clean it up a bit

Darhagonable commented 7 months ago

For now then ill do my own exports export type TDataGetApiV1Foo = ReturnType<typeof DefaultService.foo> 👍