Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created December 3, 2022 05:16
Show Gist options
  • Save leegilmorecode/5ab8c464ad217c47bec2f03457a5a238 to your computer and use it in GitHub Desktop.
Save leegilmorecode/5ab8c464ad217c47bec2f03457a5a238 to your computer and use it in GitHub Desktop.
A base class for our value objects
import { schemaValidator } from '@packages/schema-validator';
interface ValueObjectProps {
[index: string]: any;
}
export abstract class ValueObject<T extends ValueObjectProps> {
protected props: T;
constructor(props: T) {
this.props = Object.freeze(props);
}
protected validate(schema: Record<string, any>): void {
schemaValidator(schema, this.props);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment