-
Notifications
You must be signed in to change notification settings - Fork 0
enum param
awekrx edited this page May 29, 2026
·
1 revision
import { enumParam } from '@dev-suite/decorators/enum-param'
parameter
Restrict parameter to allowed enum-like values.
- Inline
includesguards - Repeated switch default errors
class FeatureService {
setMode(mode: string) {
if (!['off', 'on', 'beta'].includes(mode)) throw new Error('Invalid mode');
return this.store.set(mode);
}
}import { enumParam } from '@dev-suite/decorators/enum-param';
class FeatureService {
setMode(@enumParam({ allowed: ['off', 'on', 'beta'] }) mode: string) {
return this.store.set(mode);
}
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class ReportService {
run(format: string) {
if (!['csv', 'json'].includes(format)) throw new Error('Invalid format');
return this.exporter.run(format);
}
}import { enumParam } from '@dev-suite/decorators/enum-param';
class ReportService {
run(@enumParam({ allowed: ['csv', 'json'] }) format: string) {
return this.exporter.run(format);
}
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.