Effect CommunityEC
Effect Community3y ago
18 replies
Patrick Roza

Modeling a Class with Required Properties and Default Values

how does one model a class that requires all properties when decoding, but may provide default values in the constructor?
say:
class Something {
   constructor({ a, b }: { a: number, b?: string | undefined }) {
      this.props = { a, b: b === undefined ? "abc" : b }
   }
}
where-as b missing while decoding is an error?
Its a major common case for me when newing up objects in code, versus rehydrating them from storage, or receiving them over wire.
Was this page helpful?