Generate object literals for enums
See original GitHub issueWe’re currently rolling out this pattern.
export * from '@genql/client'
import type { PlanetscaleRegion as PlanetscaleRegion_ } from '@genql/client'
export type PlanetscaleRegion = PlanetscaleRegion_
// TODO get object literals for enums from Genql core.
export const PlanetscaleRegion = {
us_east: 'us_east',
us_west: 'us_west',
ap_northeast: 'ap_northeast',
ap_south: 'ap_south',
ap_southeast: 'ap_southeast',
eu_west: 'eu_west',
} as const
This is so that frontend code can create enum members and more (such as create zod schema types based on the enum for frontend form validation).
It would be great to have Genql ship (generate) these object literals by default.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Object literals combining enums and computed property names
I have an enum enum Action { action1 = 'action1', action2 = 'action2' };. whose values I use as computed property names in...
Read more >Use const enum values as keys of object literals · Issue #14682
I want to use values of a const enum to define object literals ** Syntactic ** const enum E { Aa = 1,...
Read more >Creating Enums in Vanilla JavaScript | Bits and Pieces
JavaScript enumeration: a basic representation · Step 1. Define a plain object literal (POJO) · Step 2. Make sure that values are constant....
Read more >13 Alternatives to enums in TypeScript
13 Alternatives to enums in TypeScript · 13.1 Unions of singleton values # · 13.2 Discriminated unions # · 13.3 Object literals as...
Read more >Handbook - Enums - TypeScript
In this generated code, an enum is compiled into an object that stores both forward ( name -> value ) and reverse (...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can now import
enumPlanetscaleRegion
and doenumPlanetscaleRegion.us_west
If you can allow a way to customize the naming pattern in the CLI/config file that would be ideal 😃
Customize examples:
I guess anything requiring transformations would be relegated to a config file, not on the CLI.