Skip to content

Spread operator should be used instead #15

@LabLamb

Description

@LabLamb

Issue

The current implementation forces us to implement all the properties in User unless we set ignoreUndefinedProperties in the Firestore SDK.

Cause

The User datatype contains a bunch of optional properties and it will become undefined if we reference it as our current implementation.

export const createUserInFirestore = async (user: User) => {

Suggested solution

We should use spread operator instead:

export const createUserInFirestore = async (user: User) => {
  const { id, ...rest } = user;
  await firestore().collection(USERS_COLLECTION_NAME).doc(id).set({
    ...rest,
    createdAt: firestore.FieldValue.serverTimestamp(),
    updatedAt: firestore.FieldValue.serverTimestamp(),
  })
}

It's also less code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions