Comments (6)
https://blog.graphqleditor.com/enums-are-still-bad
from orval.
@Wtiben, the article is misleading, because it says:
Essentially we're getting everything we would from an enum, without the drawbacks of actually using an enum.
and
key issue of ‘why not just use a const’ will remain for those who find them entirely redundant
.
I gave the answer to their question above, but I'll duplicate it here for you. With a constant, you will get a non-working code:
export type MyEnum = typeof MyEnum[keyof typeof MyEnum];
export const MyEnum = {
testA: 'testA',
testB: 'testB',
testC: 'testC',
} as const;
const a = MyEnum.testA;
const arr = [MyEnum.testB, MyEnum.testC];
arr.includes(a); // TS2345: Argument of type '"testA"' is not assignable to parameter of type '"testB" | "testC"'.
At the same time, with enum you will get a working and more concise code:
export enum MyEnum {
testA = 'testA',
testB = 'testB',
testC = 'testC',
}
const a = MyEnum.testA;
const arr = [MyEnum.testB, MyEnum.testC];
arr.includes(a);
Besides, I don't insist on generating enum by default. this can be done by some flag in the config
from orval.
PR is welcome!
from orval.
Hey, I've taken up the gauntlet and contributed my first PR to the project with an optional configuration parameter to generate native Typescript enums and the code to handle it.
from orval.
@dsthode sent you 1 review comment
from orval.
@melloware thank you for the comment, I've performed the changes requested.
from orval.
Related Issues (20)
- Node16 or bundler module resolution causes TS2742 error HOT 1
- Missing import of enum const in generated mock when using split mode HOT 5
- Mock TypeError custom override HOT 7
- Possibility of TS2563 error for mock generation HOT 5
- TS2300 Duplicate identifier: duplicated imports when `mock` enabled HOT 7
- Allow overriding entire handler function in generated MSW handlers, not just response object
- Invalid typescript generation for empty schema HOT 4
- msw generation does not import used models HOT 1
- Mock generation doesn't guarantee the required property mocking
- Is possible ignore the changes in the line of OpenAPI spec version ? HOT 2
- Another duplicate export edge case
- Specify mock property overrides for a specific schema HOT 2
- Support replacing types with custom ones when transforming the input HOT 5
- React Query: Regression in 6.25.0 caused by #1207 HOT 5
- Is possible ignore the changes in the line of OpenAPI spec version ?
- Orval generates wrong import paths in ESM-only package HOT 3
- Pass an additional option object in fetcher function when using custom axios instance HOT 5
- usePrefetch+useSuspenseQuery incorrectly generates prefetchSuspenseQuery calls
- bug: readonly fields missing from mutation function input types
- Regression when updating from 6.21 to 6.22.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orval.