Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enums.gen to index.ts #396

Closed
mlankamp opened this issue Apr 16, 2024 · 6 comments · Fixed by #399
Closed

Add enums.gen to index.ts #396

mlankamp opened this issue Apr 16, 2024 · 6 comments · Fixed by #399
Assignees
Labels
bug 🔥 Something isn't working

Comments

@mlankamp
Copy link
Contributor

mlankamp commented Apr 16, 2024

Description

With #358 the enums are written into a separate file, this breaks all our existing imports.

Is it possible to add export * from './enums.gen' to index.ts?

What was the exact reason to move the enums into their own file?

@mlankamp mlankamp added the bug 🔥 Something isn't working label Apr 16, 2024
@mrlubos
Copy link
Member

mrlubos commented Apr 16, 2024

Yeah shouldn't be a problem to add enums to index. Though the intent is to remove all re-exported modules and you'd be importing each layer as needed (types, services, enums, schemas) https://heyapi.vercel.app/openapi-ts/migrating.html#deprecated-exports-from-index-ts

@mrlubos mrlubos self-assigned this Apr 16, 2024
@mlankamp
Copy link
Contributor Author

mlankamp commented Apr 16, 2024

Ah, hadn't seen that page yet. If the goal is to remove them from index.ts, then I understand.

Personally I don't like the new naming scheme (.gen.ts) for the files as the import would look like:

import type { Model } from 'client/models.gen';
import { Enum } from 'client/enums.gen';
import { $Schema } from 'client/schemas.gen';
import { DefaultService } from 'client/services.gen';

Maybe it's an idea to give index.ts a new name, so people can create the index.ts file themself.

@mrlubos
Copy link
Member

mrlubos commented Apr 16, 2024

We could do that. This pattern is inspired by TanStack Router with the goal of reducing confusion around which files are generated. It might be easier to migrate if we provide a backward compatible setting though, good suggestion

@jordanshatford
Copy link
Collaborator

@mrlubos NOTE: if we remove the 'Enum' Suffix from generated enums there may be conflicts between the types generate and the enums. Making it cause issues exporting both in the index.ts

@mrlubos
Copy link
Member

mrlubos commented Apr 17, 2024

I have only re-exported enums from index file for now, don't want to introduce complexity around transforming names right now. Will give it a while, see if you still hate it

@mrlubos
Copy link
Member

mrlubos commented Apr 17, 2024

@mlankamp now we have another issue. In 0.39.0, enums correctly use the same name whether you use JavaScript or TypeScript. However, this is a breaking change for TypeScript users. At the same time, we can't revert that change in combination with this request since there would be export clashes. I think we will have to revert enums export from index.ts in the release addressing the naming change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants