diff --git a/404.html b/404.html index a0e8865..c734e31 100644 --- a/404.html +++ b/404.html @@ -4,7 +4,7 @@
Const assertions must be used over enums.
-While enums can still fulfill similar use cases as const assertions, we tend to avoid using them. Some of the reasonings as mentioned in TypeScript documentation - Const enum pitfalls, Objects vs Enums, Reverse mappings etc.
+While enums can still fulfill similar use cases as const assertions, we tend to avoid using them.
+The TypeScript documentation highlights several reasons for this preference, such as:
// ❌ Avoid using enums
enum UserRole {
GUEST,
MODERATOR,
ADMINISTRATOR,
}
enum Color {
PRIMARY = '#B33930',
SECONDARY = '#113A5C',
BRAND = '#9C0E7D',
}
// ✅ Use const assertion
const USER_ROLES = ['guest', 'moderator', 'administrator'] as const;
type UserRole = (typeof USER_ROLES)[number]; // Type "guest" | "moderator" | "administrator"
// Use satisfies if UserRole type is already defined - e.g. 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',
} as const;
type Color = typeof COLOR;
type ColorKey = keyof Color; // Type "primary" | "secondary" | "brand"
type ColorValue = Color[ColorKey]; // Type "#B33930" | "#113A5C" | "#9C0E7D"