Skip to content

Generate correct type for IndexedEnum #40

Open
@Cardu

Description

@Cardu

requirements

When the Scala model is a enumero IndexedEnum, by default it's implicitly converted to a number.
Metarpheus treats it like it's a CaseEnum, expecting it's string value, and this produces an error on the client side.

specs

for an IndexedEnum, like:

@indexedEnum trait Priority {
  type Index = Int
  object High { 1 }
  object Medium { 2 }
  object Low { 3 }
}

the current generated code is:

export type Priority = 
  | 'High'
  | 'Medium'
  | 'Low'

export const Priority = t.keyof({
  High: true,
  Medium: true,
  Low: true
}, 'Priority')

but should be something like:

export interface Priority extends Newtype<{readonly priority : number}, number> {}
export const Priority = fromNewtype<Priority>()(t.number)

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