Skip to content

Generate enum method results - #297

Merged
joetannenbaum merged 1 commit into
nextfrom
generate-typescript-funcs
Aug 10, 2026
Merged

Generate enum method results#297
joetannenbaum merged 1 commit into
nextfrom
generate-typescript-funcs

Conversation

@joetannenbaum

Copy link
Copy Markdown
Collaborator

If an enum has methods like label() or description(), Wayfinder now calls them for each case at generation time and writes the results to a companion constant.

export const OrderStatus = { Pending, Shipped, Delivered } as const

export const OrderStatusMeta = {
    pending: { label: "Awaiting Payment", color: "gray", isFinal: false },
    shipped: { label: "On Its Way", color: "gray", isFinal: false },
    delivered: { label: "Delivered", color: "green", isFinal: true },
} as const

It's keyed by case value rather than case name, so a value coming back from the server works as the lookup key: OrderStatusMeta[post.status].label.

Only methods with no required arguments get called. Static, magic, protected and private methods are skipped, along with anything returning void or never. Strings, numbers, booleans, null, arrays, backed enums, JsonSerializable, Arrayable and Stringable all convert; anything else is dropped. If a method throws for a single case, only that case loses the entry.

Nothing existing changes shape. The case constants, the enum object and the App.Enums.* union types are untouched, and no companion constant is emitted for an enum with no eligible methods.

Since this runs your code at generation time it's off by default, behind WAYFINDER_GENERATE_ENUM_METHODS. Worth knowing that a label() returning __('post.draft') bakes in whichever locale the command ran under.

@joetannenbaum
joetannenbaum merged commit 55b8dc7 into next Aug 10, 2026
11 checks passed
@joetannenbaum
joetannenbaum deleted the generate-typescript-funcs branch August 10, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant