dotansimha / dotansimha/graphql-code-generator

make `enumsAsTypes` export a const of the values as well as the type

Open
#8,745 2 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Is your feature request related to a problem? Please describe.

If I want to use `enumsAsTypes` because I want the string union, I have no way to get the list of values of the string union. There are cases in which I want both the string union AND the list of all values in my enum. You _could_ use `enumsAsConsts`, but one could also want to use `enumsAsTypes` (for example, you might not like the weird capitalization things that happen with keys in the generated const).

This change seems pretty harmless - 99% backwards compatible (pending small questions) and adds to the existing feature.

Some questions for you:
- Should we do something better with naming? `MyEnumValues` or something? need to avoid collisions

### Describe the solution you'd like

When `enumsAsTypes` is true, I want there to be the following lines:

```
export const MyEnum = ['A', 'B'] as const;
export type MyEnum = typeof MyEnum[number];
```

### Describe alternatives you've considered

_No response_

### Is your feature request related to a problem? Please describe.

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.