-
Notifications
You must be signed in to change notification settings - Fork 0
default value
awekrx edited this page May 29, 2026
·
1 revision
import { defaultValue } from '@dev-suite/decorators/default-value'
property
Provide default property value when field is unset.
- Constructor field default boilerplate
- Getter-based lazy init guards
class SessionState {
token?: string;
getToken() {
if (!this.token) this.token = 'guest';
return this.token;
}
}import { defaultValue } from '@dev-suite/decorators/default-value';
class SessionState {
@defaultValue('guest')
token!: string;
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class MetricsContext {
correlationId?: string;
ensureId() {
if (!this.correlationId) this.correlationId = crypto.randomUUID();
return this.correlationId;
}
}import { defaultValue } from '@dev-suite/decorators/default-value';
class MetricsContext {
@defaultValue(() => crypto.randomUUID())
correlationId!: string;
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.