Open alita-moore opened 8 months ago
If the value can only be a single value, I would expect it to be a const
. Is there any advantage to having it as a single-element enum?
Using enums in Typescript except a standard string is helpful for many reasons. For example,
type someType = { key: Enum.Apple, value: string }
In the future
type SomeType = { key: Enum.Apple value: string } | { key: Enum.Orange value: number }
Dependents on SomeType would not need to start using an Enum once the new value is added which reduces overhead.
switch (EnumValue) { case Enum.Apple: Do something default: // @ts-expect-error -- this will error if a case is missed above EnumValue.toString() }
By right clicking the Enum definition you can find where in the code that value is indexed. This simplifies finding and replacing usages.
This is a few examples but there are more. Using an Enum is helpful even if only one value. Specifically in Typescript. But perhaps a more important point is whether or not it's intuitive for this software to change the input type based on the length of the Enum. It seems to be more intuitive that if an Enum is the input then an Enum will be the output, no?
Description
When you export an enum with one value it maps to a constant in the schema, but I expect it to map to an enum with one element.
Reproduction
see the reproduction in the following codesandbox: https://codesandbox.io/p/sandbox/lucid-kirch-r3rxlg
in short, the input typescript file is
And the command to compile into json schema is
Expected Results
I expect the results to be an enum with one element
Actual Results