Added enums use case (#1428)
This commit is contained in:
@ -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
|
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
|
```tsx
|
||||||
// ❌ Bad, utilizes an enum
|
// ❌ Bad, utilizes an enum
|
||||||
enum Color {
|
enum Color {
|
||||||
@ -153,6 +151,25 @@ let color = Color.Red;
|
|||||||
let color: "red" | "green" | "blue" = "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
|
## Styling
|
||||||
|
|
||||||
### Use StyledComponents
|
### Use StyledComponents
|
||||||
|
|||||||
Reference in New Issue
Block a user