Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread operator should be used instead #15

Open
LabLamb opened this issue Mar 16, 2022 · 0 comments
Open

Spread operator should be used instead #15

LabLamb opened this issue Mar 16, 2022 · 0 comments

Comments

@LabLamb
Copy link

LabLamb commented Mar 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant