Skip to content

Improve useUnion enum transformation. #990

@aFarkas

Description

@aFarkas

I have the problem that Enum don't seem to be exported in the schema + the transformation of enum to union could be heavily improved.

Current situation

Models:

export type TypeEnum = 'ONE' | 'TWO' | 'THREE';

Schemas:

export const $TypeEnum = {
    type: 'Enum',
} as const;

Improved code

Models:

export const TypeEnum = {
  ONE: 'ONE',
  TWO: 'TWO',
  THREE: 'THREE',
} as const;

export type TypeEnum = typeof TypeEnum[keyof typeof TypeEnum];

Schemas:

export const $TypeEnum = {
    type: 'Enum',
    items: ['ONE', 'TWO', 'THREE'],
} as const;

See also https://maxheiber.medium.com/alternatives-to-typescript-enums-50e4c16600b1 and maybe this is also an improvement for #988

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions