Currently, the following GraphQL type
enum Color {
RED
BLUE
}
generates the following TypeScript type
export enum Color {
RED = "RED",
BLUE = "BLUE",
}
I would like to have the option to generate the following type instead:
export type Color = "RED" | "BLUE";
This definition provides the same safety, but is more efficient and works better with TypeScript structural typing.
Unrelated: consider generating const enum instead of enum.
Related:
+1, having an enum is annoying for me. I don't want to import the enum and to Enum.Value, I just want to use string literals, it's as safe as enums and works nicely
String enums still have a slight advantage in that you can find all usages of it. String constants actually can be searched by "find all usages", which was a nice surprise (:tada:), but typescript can't distinguish "intentional" uses from "coincidental" uses of a given string constant -- the string enums work to disambiguate them, especially if there are multiple different enums in your schema that happen to partially overlap in some of the values; it would be good to know _which_ enum is being referred to when the value appears in code.
I think this might be mitigated by the planned "unique types" feature, but I haven't seen if it can be made to work for this use case.
export type Color = "RED" | "BLUE";
These also work better if you have a js codebase and are using checkjs, there is no way (AFAIK) to import and use the typescript enum.
I've fixed this in #1750 馃檮
Most helpful comment
I've fixed this in #1750 馃檮