Skip to main content
Version: 1.x

Quickstart

typescript
class Money extends ValueObject.define({
parse: zodResolver(
z.object({
cents: z.number(),
currency: z.string()
})),
}) {}
 
 
const money = Money.create({
cents: 10,
currency: 'AUD'
})
 
const serialized = { ...money.asJSON() }
const serialized: { cents: number; currency: string; }
 
// Missing parameters. Cannot be created.
Money.create({
Argument of type '{ cents: number; }' is not assignable to parameter of type 'Money | MarkUndefinedAsOptional<{ cents: number; currency: string; }>'. Type '{ cents: number; }' is not assignable to type 'MarkUndefinedAsOptional<{ cents: number; currency: string; }>'. Property 'currency' is missing in type '{ cents: number; }' but required in type '{ cents: number; currency: string; }'.2345Argument of type '{ cents: number; }' is not assignable to parameter of type 'Money | MarkUndefinedAsOptional<{ cents: number; currency: string; }>'. Type '{ cents: number; }' is not assignable to type 'MarkUndefinedAsOptional<{ cents: number; currency: string; }>'. Property 'currency' is missing in type '{ cents: number; }' but required in type '{ cents: number; currency: string; }'.
cents: 10
})