I had the following code using signals which I implemented with Angular 16.x:
protected errors = signal<string[]>([]);
@Input()
set error(error: string) {
if (error) {
if (this.errors().indexOf(error) === -1) {
this.errors.mutate((errors: any) => errors.push(error));
}
} else {
this.errors.set([]);
}
}
After upgrading the version to Angular 17.x, I trying to run the unit test, I face the following error message:
Property 'mutate' does not exist on type 'WritableSignal<string[]>'
I assume it's because of mutate has been removed. Any fix, alternative or hint how to fix this.
As of v17, signal don't support mutations anymore.
You'll have to refactor to use signal.update() and return a new instance to mark the consumers as dirty.
this.errors.update((errors: any) => ([...errors, error]));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With