Skip to content

Enum arrays in type definitions generate incorrect TypeScript types #240

@genu

Description

@genu

When defining an enum array field in a ZenStack type definition, the generated TypeScript type produces a union of individual enum values instead of an array of enum values.

ZModel Schema:

  enum ShirtColor {
      Black
      White
      Red
      Green
      Blue
  }

  type Configuration {
      teamColors    ShirtColor[]?  // This should be an optional array
  }

Generated Schema (correct):

  In .generated/zenstack/schema.ts:
  teamColors: {
      name: "teamColors",
      type: "ShirtColor",
      optional: true,
      array: true  // ✅ Correctly marked as array
  }

Generated type:

type TestConfiguration = TypeDefResult<SchemaType, "Configuration">
// teamColors is typed as "Black" | "White" | "Red" | "Green" | "Blue" | "Yellow" | "Cyan" | "Magenta" | "Gray" | null;

Excpected

For an enum array field like teamColors ShirtColor[]?, the generated TypeScript type should be teamColors?: ShirtColor[] | null | undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions