Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Property mutate does not exist on type WritableSignal<string[]>

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.

like image 209
k.vincent Avatar asked Oct 22 '25 05:10

k.vincent


1 Answers

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]));
like image 50
Matthieu Riegler Avatar answered Oct 23 '25 19:10

Matthieu Riegler