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

Typings: Cannot destructure array anymore when calling getAll #501

Closed
ushu opened this issue Dec 28, 2018 · 3 comments
Closed

Typings: Cannot destructure array anymore when calling getAll #501

ushu opened this issue Dec 28, 2018 · 3 comments
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@ushu
Copy link

ushu commented Dec 28, 2018

Since PR #443 has been merged, the signature for Firestore.getAll() has changed from

getAll(...documents: DocumentReference[]): Promise<DocumentSnapshot[]>

to

getAll(documentRef: DocumentReference, ...moreDocumentRefsOrReadOptions: Array<DocumentReference|ReadOptions>): Promise<DocumentSnapshot[]>

with this change, we cannot use array destructuring anymore to "prepare" the refs to fetch in advance.

For example, I used to do the following:

// step 1 - select the documents to fetch
const userIDs = ... 
const usersRef = admin.firestore().collection("users")
const userRefs: DocumentReference[] = userIDs.map(id => usersRef.doc(id))

// step 2 - Grab-them-all
const snaps = await admin.firestore().getAll(...userRefs)

this won't work anymore (I tried to update TS but it did not fix it), the only workaround is to do something like:

const snaps = await admin.firestore().getAll(
  // extract the first item
  userRefs[0],
  // and then process the remaining elements
  ...(userRefs.slice(1))
)

Environment details

  • OS: Mojave
  • Node.js version: 10.12.0 (TS 3.2.2)
  • npm version: 6.4.1
  • @google-cloud/firestore version: 0.19.0

Steps to reproduce

  1. Create a project with Typescript support
  2. Type the code above (with .getAll(...userRefs)) → it won't compile

Edit: added #502 to restore previously-working behavior

Regards

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Dec 29, 2018
@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Jan 2, 2019
@mikelehen mikelehen self-assigned this Jan 2, 2019
@mikelehen
Copy link
Contributor

I'll take a look at this later today, but I wonder if we can solve this by having 2 overloads.

@cxam
Copy link
Contributor

cxam commented Jan 8, 2019

@mikelehen not sure if you had any time to look at this yet but I've just created a PR (#515) that fixes this issue by overloading the getAll function.

@mikelehen
Copy link
Contributor

Thanks very much! Just left a comment on the PR. Unfortunately I think I was misguided to suggest using overloads in this case. :-/

@google-cloud-label-sync google-cloud-label-sync bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants