Enums
Oidis uses a class-based enum pattern built on BaseEnum from io-oidis-commons. This gives you type-safe constants plus runtime introspection — something native TypeScript enum cannot provide.
Package: io-oidis-commons
import { BaseEnum } from "@io-oidis-commons/Io/Oidis/Commons/Primitives/BaseEnum.js";
Creating an Enum
Extend BaseEnum and declare values as public static readonly string constants:
import { BaseEnum } from "@io-oidis-commons/Io/Oidis/Commons/Primitives/BaseEnum.js";
export class EANType extends BaseEnum {
public static readonly PRODUCTION : string = "D";
public static readonly CONSUMPTION : string = "O";
}
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Class name | PascalCase, descriptive | EANType, RecordStatus, DataFormatType |
| Constants | UPPER_SNAKE_CASE | PRODUCTION, UTF8, URL_ENCODED |
| Values | Meaningful short strings | "D", "utf8", "active" |
File Placement
Place enum classes in the Models/ directory alongside other domain types. Enums are not @Entity models — they are standalone classes.
Usage
Direct Comparison
if (summary.Type === EANType.PRODUCTION) {
// handle production EAN
}
Runtime Reflection
BaseEnum provides static methods for runtime introspection via the Oidis Reflection system:
| Method | Returns | Description |
|---|---|---|
Contains($value) | boolean | Check if a value belongs to the enum |
getKey($value) | string | Reverse-lookup: value → constant name |
getProperties() | string[] | List all constant names |
ClassName() | string | Fully qualified class name |
EANType.Contains("D"); // true
EANType.Contains("X"); // false
EANType.getKey("D"); // "PRODUCTION"
EANType.getProperties(); // ["PRODUCTION", "CONSUMPTION"]
Interface Type Annotations
When an interface field holds an enum value, type it as string — not as a union literal. BaseEnum values are string at the type level:
// ✅ Correct — works with BaseEnum
export interface IEDCReportEAN {
ean : string;
type : string;
}
// ❌ Wrong — hardcoded union, cannot use BaseEnum
export interface IEDCReportEAN {
ean : string;
type : "D" | "O";
}
Model Integration
Enums work naturally with @Property on model fields:
@Property({ type: RecordStatus, default: RecordStatus.ACTIVE })
public declare Status : RecordStatus;
The framework serializes/deserializes the string value. See Entity & Property for details.
BaseEnum vs TypeScript enum
| Feature | BaseEnum | TypeScript enum |
|---|---|---|
| Runtime reflection | ✅ Contains, getKey, getProperties | ❌ None |
| Oidis Reflection integration | ✅ Discovered by namespace scanner | ❌ Not a class |
@Property type support | ✅ Works as model field type | ❌ Not supported |
| Tree-shakeable | ✅ Standard class | ⚠️ Generates extra JS code |
| Exhaustiveness checking | ❌ Not enforced by TS compiler | ✅ switch exhaustiveness |
Rule: Always use BaseEnum in Oidis projects. TypeScript native enum does not integrate with the framework's reflection and model systems.
See also: Models Overview | Entity and Property | Reflection