Skip to content

Instantly share code, notes, and snippets.

View pauloafpjunior's full-sized avatar

Paulo Júnior pauloafpjunior

  • Federal University of Lavras
  • Lavras/MG/Brazil
View GitHub Profile
@pauloafpjunior
pauloafpjunior / !error-handling.ts
Last active February 15, 2022 06:14
Error handling in TypeScript: an alternative approach
// Value object
class CityName {
static readonly MIN_LEN_NAME: number = 3
static readonly MAX_LEN_NAME: number = 100
private constructor(private _name: string) { }
// Factory method with validation rules
static create(name: string): [CityName, Error] {
@pauloafpjunior
pauloafpjunior / !clean-arch.ts
Last active February 15, 2022 06:14
The simplest clean architecture example
namespace Domain {
export class Hero {
private constructor(private _name: string) { }
get name(): string { return this._name; }
static create(name: string): [Hero, Error] {
if (!name || name.trim().length < 3 || name.trim().length > 100) {
return [null, new InvalidNameError(name)]
}