Skip to content

[REQ] [typescript-axios] Object value enums #10943

@jmroon

Description

@jmroon

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 generator actually already implements this by default (stringEnums = false). 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;
}

Alternative Solutions

It would be even greater if this could be extended to all typescript generators, but I'm not sure if their functionality is centralized in any way.

I did take a quick look at the source, but my Java-fu is weak and I can't find the obvious place to implement the change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions