Basically what I'm trying to achieve is send info to the server without quotations e.g Admin instead of "Admin", but as we all know Graphql will throw an error is the variable is not defined or is not in quotations.
we can create a enum like property as below: const adminEnum = { Admin: 'Admin'};
An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). To create an enum , use the enum keyword (instead of class or interface), and separate the constants with a comma.
Enums or enumerations are a new data type supported in TypeScript. Most object-oriented languages like Java and C# use enums. This is now available in TypeScript too. In simple words, enums allow us to declare a set of named constants i.e. a collection of related values that can be numeric or string values.
The easiest way to define an enum would be to use Object. freeze() in combination with a plain object. This will ensure that the enum object cannot be mutated. const daysEnum = Object.
we can create a enum like property as below:
const adminEnum = { Admin: 'Admin'};
Hope I got the question right.
you can use enum with typeScript
in react-native
like describe in the link
sample code is
enum Direction {
Up = 1,
Down,
Left,
Right,
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With