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

[REQ][typescript-fetch] Allow string literal unions instead of string enums #11480

Closed
kasperpeulen opened this issue Feb 1, 2022 · 1 comment · Fixed by #11976
Closed

[REQ][typescript-fetch] Allow string literal unions instead of string enums #11480

kasperpeulen opened this issue Feb 1, 2022 · 1 comment · Fixed by #11976

Comments

@kasperpeulen
Copy link
Contributor

kasperpeulen commented Feb 1, 2022

Is your feature request related to a problem? Please describe.

While the typescript interfaces generated for the model can be fully compatible with client side models, this is not the case with enums as different string enums cannot be compatible on the client side. Typescript enums are problematic, and the typescript community has a better solution.

Implemented this would allow the client side models and server side models to be entirely decoupled, as enums are the only thing standing in the way of that at the moment.

I realize that many people likely use the server models directly, but a flexible approach would be preferable.

Describe the solution you'd like

The typescript-angular and typescript-axios generator actually already implements this by default (stringEnums = false).

See this recent merge request:
#11368

It creates an object value enum as such:

export interface Model {
  type: Model.TypeEnum;
}
export namespace Model{
  export type TypeEnum = 'ONE' | 'TWO' | 'THREE';
  export const TypeEnum = {
    ONE: 'ONE' as TypeEnum,
    ONE: 'TWO' as TypeEnum,
    ONE: 'THREE' as TypeEnum,
  } as const;
}
@kasperpeulen
Copy link
Contributor Author

Relates to:
#10943

I copy pasted most of this issue, as the issue is the same for axios as for fetch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant