You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Operations like create, set, get are correctly typed but I faced an issue when trying to do update operation to change map field of the document.
Let's say if I want to update sample1 field of preferences, this throws type error:
exportasyncfunctionupdatePreferences({id, ...payload}: UpdateData<UserDocument>&{id: string}){// throws type errorawaituserCollection.doc(id).update(payload);}
Note that UpdateData type is imported from @react-native-firebase/firestore and it allows user to pass payload with dot notation to update map fields:
{ 'preferences.sample1': 'something' }
This is throwing error because update accepts Partial<UserDocument>.
A workaround was to not type the collection which then makes update to accept Partial<{[x: string]: any;}>.
This isn't something I want because I wanted to enforce type to prevent passing wrong/non-existing values.
So a workaround that I'm using is to assert type as any:
awaituserCollection.doc(id).update(payloadasany);
Then I thought that when typing collection by passing generic like const userCollection = firestore().collection<UserDocument>('users');, then update operation should accept UpdateData<UserDocument> instead of Partial<UserDocument>.
Is there any reason why it isn't using UpdateData?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, when typing a collection by passing generic like this:
Operations like create, set, get are correctly typed but I faced an issue when trying to do
update
operation to change map field of the document.Let's say if I want to update
sample1
field ofpreferences
, this throws type error:Note that
UpdateData
type is imported from@react-native-firebase/firestore
and it allows user to pass payload with dot notation to update map fields:This is throwing error because
update
acceptsPartial<UserDocument>
.A workaround was to not type the collection which then makes
update
to acceptPartial<{[x: string]: any;}>
.This isn't something I want because I wanted to enforce type to prevent passing wrong/non-existing values.
So a workaround that I'm using is to assert type as any:
Then I thought that when typing collection by passing generic like
const userCollection = firestore().collection<UserDocument>('users');
, thenupdate
operation should acceptUpdateData<UserDocument>
instead ofPartial<UserDocument>
.Is there any reason why it isn't using
UpdateData
?Beta Was this translation helpful? Give feedback.
All reactions