Added enums use case (#1428)

This commit is contained in:
Lucas Bordeau
2023-09-04 11:35:27 +02:00
committed by GitHub
parent c998c039ec
commit 2ac32e42c5

View File

@@ -135,8 +135,6 @@ type MyType = {
You can see why TypeScript recommend avoiding enums here : https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#enums
However, GraphQL codegen will generate enums, so you can't avoid them completely, but avoid creating new ones.
```tsx
// ❌ Bad, utilizes an enum
enum Color {
@@ -153,6 +151,25 @@ let color = Color.Red;
let color: "red" | "green" | "blue" = "red";
```
#### GraphQL and internal libs
We recommend using enums that are generated by GraphQL codegen.
We also recommend using an enum when using an internal lib, so the internal lib doesn't have to expose a string literal type that is not related to the internal API.
Example :
```TSX
const {
setHotkeyScopeAndMemorizePreviousScope,
goBackToPreviousHotkeyScope,
} = usePreviousHotkeyScope();
setHotkeyScopeAndMemorizePreviousScope(
RelationPickerHotkeyScope.RelationPicker,
);
```
## Styling
### Use StyledComponents