Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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[]>’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I assume it’s because of mutate has been removed. Any fix, alternative or hint how to fix this.

>Solution :

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]));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading