-
Notifications
You must be signed in to change notification settings - Fork 0
validate
awekrx edited this page May 29, 2026
·
1 revision
import { validate } from '@dev-suite/decorators/validate'
property
Validate property assignment with predicate.
- Manual
if/throwin every setter - Field-validation logic scattered across methods
class TransferForm {
private _amount = 0;
set amount(next: number) {
if (next <= 0) throw new Error('amount must be positive');
this._amount = next;
}
}import { validate } from '@dev-suite/decorators/validate';
class TransferForm {
@validate(({ value }) => Number(value) > 0)
amount = 0;
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class SignupState {
private _email = '';
set email(next: string) {
if (!next.includes('@')) throw new Error('invalid email');
this._email = next;
}
}import { validate } from '@dev-suite/decorators/validate';
class SignupState {
@validate(({ value }) => String(value).includes('@'))
email = '';
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.