I have a Pinia + TypeScript store named user.ts
with the following structure:
import { User } from 'firebase/auth';
import { defineStore } from 'pinia';
export const useUserStore = defineStore('user', {
state: () =>
({
displayName: null,
email: null,
emailVerified: null,
isAnonymous: null,
metadata: null,
multiFactor: null,
phoneNumber: null,
photoURL: null,
providerData: null,
providerId: null,
refreshToken: null,
tenantId: null,
uid: null,
} as unknown as User),
actions: {
setPhotoURL(photoURLData: string | null) {
this.photoURL = photoURLData; //<-- ERROR HERE
},
},
});
The state object represents a FireBase User.
I'm trying to update the photoURL
value using the setPhotoURL()
action.
However, I encountered a TypeScript error related to the readonly property of photoURL
:
Cannot assign to 'photoURL' because it is a read-only property. ts(2540)
Can anyone help me understand what I'm doing wrong?
Is this the correct approach for updating state in this setup?