Skip to content

Commit

Permalink
Added enums use case (#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbordeau authored Sep 4, 2023
1 parent c998c03 commit 2ac32e4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions docs/docs/developer/frontend/style-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2ac32e4

Please sign in to comment.