Skip to content

Commit

Permalink
update docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
mkosir committed Dec 15, 2024
1 parent 0aa245e commit eb0e684
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions website/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -658,34 +658,21 @@ The TypeScript documentation highlights several reasons into the limitations and
```ts
// ❌ Avoid using enums
enum UserRole {
GUEST,
MODERATOR,
ADMINISTRATOR,
}

enum Color {
PRIMARY = '#B33930',
SECONDARY = '#113A5C',
BRAND = '#9C0E7D',
GUEST = 'guest',
MODERATOR = 'moderator',
ADMINISTRATOR = 'administrator',
}

// ✅ Use const assertions
const USER_ROLES = ['guest', 'moderator', 'administrator'] as const;
type UserRole = (typeof USER_ROLES)[number]; // Type "guest" | "moderator" | "administrator"

// Use 'satisfies' if the UserRole type is already defined, e.g., in a database schema model
type UserRoleDB = ReadonlyArray<'guest' | 'moderator' | 'administrator'>;
const AVAILABLE_ROLES = ['guest', 'moderator'] as const satisfies UserRoleDB;

const COLOR = {
primary: '#B33930',
secondary: '#113A5C',
brand: '#9C0E7D',
const USER_ROLE = {
guest: 'guest',
moderator: 'moderator',
administrator: 'administrator',
} as const;

type Color = typeof COLOR;
type ColorKey = keyof Color; // Type "primary" | "secondary" | "brand"
type ColorValue = Color[ColorKey]; // Type "#B33930" | "#113A5C" | "#9C0E7D"
type UserRole = keyof typeof USER_ROLE;

const isGuest = (role: UserRole) => role === USER_ROLE.guest;
```
### Type Union & Boolean Flags
Expand Down

0 comments on commit eb0e684

Please sign in to comment.