Effect CommunityEC
Effect Community2w ago
2 replies
bebenzer

Mutating a Schema Instance in Effect Typescript

how to mutate a schema instance?
I have this class:
class Foo extends Schema.Class<Foo>('Foo')({
    freeAmount: Schema.Number,
}) {
    doSomething(amount: number) {
        this.freeAmount = amount
    }
}
const foo = Foo({ freeAmount: 50 })
foo.doSomething(1)


as every prop is readonly I can't mutate them, should I instead return a new instance of Foo and reassign my foo variable?
doSomething(amount: number) {
  return new Foo({...this, freeAmount: amount})
}
let foo = new Foo({freeAmount: 50})
foo = doSomething(1)
Was this page helpful?