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

feat(firestore, types): support Generic Types #3810

Merged
merged 13 commits into from
Sep 4, 2020

Conversation

franciscosolla
Copy link
Contributor

Updates firestore types to generic types, as is in the firestore web SDK.
Allows to define specific document data types ensuring type safe operations with collections and documents, plus the convenience of automatic auto-complete from type defined document data.

Description

I use type defined document data with firebase in my projects. Because the react-native-firebase implementation of firestore is not type generic I find myself replicating the type file to make then generic in my projects. As I have seen other people with the same problem, I decided to commit the types I've been using.

Related issues

Release Summary

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan


Think react-native-firebase is great? Please consider supporting the project with any of the below:

Updates firestore types to generic types, as is in the firestore web SDK.
Allows to define specific document data types ensuring type safe operations with collections and documents, plus the convenience of automatic auto-complete from type defined document data.
@CLAassistant
Copy link

CLAassistant commented Jun 20, 2020

CLA assistant check
All committers have signed the CLA.

@mikehardy
Copy link
Collaborator

Cool! Has a CI fail though, which I think would be resolved by simply opening the root of the monorepo in Visual Studio Code, re-opening the file, and asking it to reformat. Or perhaps from command-line asking prettier to auto-fix? I have it run as a save-hook on Code now so I'm not sure if it's configured correctly for command line


/home/runner/work/react-native-firebase/react-native-firebase/packages/firestore/lib/index.d.ts
##[error]    93:5   error  Replace `··[key:·string]:·DocumentFieldType` with `[key:·string]:·DocumentFieldType;`                                                                                                                      prettier/prettier
##[error]   554:80  error  Insert `⏎···`                                                                                                                                                                                              prettier/prettier
##[error]  1319:13  error  Replace `callback:·(result:·QueryDocumentSnapshot<T>,·index:·number)·=>·void,·thisArg?:·any` with `⏎······callback:·(result:·QueryDocumentSnapshot<T>,·index:·number)·=>·void,⏎······thisArg?:·any,⏎····`  prettier/prettier
##[error]  1552:48  error  Replace `documentRef:·DocumentReference<T>` with `⏎······documentRef:·DocumentReference<T>,⏎····`                                                                                                          prettier/prettier
##[error]  1605:51  error  Replace `documentRef:·DocumentReference<T>,·data:·Partial<T>` with `⏎······documentRef:·DocumentReference<T>,⏎······data:·Partial<T>,⏎····`                                                                prettier/prettier
##[error]  1727:51  error  Replace `documentRef:·DocumentReference<T>,·data:·T` with `⏎······documentRef:·DocumentReference<T>,⏎······data:·T,⏎····`                                                                                  prettier/prettier
##[error]  1853:55  error  Replace `collectionPath:·string` with `⏎······collectionPath:·string,⏎····`                                                                                                                                prettier/prettier

@Salakar Salakar changed the title Updates Firestore Types to Generic Types feat(firestore) : improve types to support Generic Types Aug 15, 2020
@mikehardy
Copy link
Collaborator

Hi @franciscosolla ! Sorry for the delay in reviewing this. I like the change a lot, I'm leaning towards merging it but I'd like to ask - are you certain this is not a breaking change? Or will this break typings for any of the users?

I have no problem with breaking changes, but I do have a problem with accidentally breaking people without it being a semantic-version major release is all, and I want to mark it correctly.

I'll try to test this locally in my project as well to cross-check

Thanks!

@mikehardy mikehardy added the Workflow: Waiting for User Response Blocked waiting for user response. label Aug 15, 2020
@vercel
Copy link

vercel bot commented Aug 20, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/invertase/react-native-firebase/i6txvz1is
✅ Preview: https://react-native-firebase-git-fork-franciscosolla-patch-1.invertase.vercel.app

@mikehardy mikehardy changed the title feat(firestore) : improve types to support Generic Types feat(firestore, types): support Generic Types Sep 4, 2020
@mikehardy
Copy link
Collaborator

We have added a feature to the repo where a patch-package file is generated for any changes so that others may easily test, the patches that implement this change are here: https://github.com/invertase/react-native-firebase/suites/1145045506/artifacts/16455376

I will test them myself to see if the typings still work in my work project, without regression

@vercel vercel bot temporarily deployed to Preview September 4, 2020 17:25 Inactive
Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change applied to harmonize the DocumentData type with firebase-js-sdk this seems to work fine in my work project

@mikehardy mikehardy added Workflow: Pending Merge Waiting on CI or similar and removed Workflow: Waiting for User Response Blocked waiting for user response. labels Sep 4, 2020
@mikehardy mikehardy merged commit f81e08e into invertase:master Sep 4, 2020
@mikehardy mikehardy removed the Workflow: Pending Merge Waiting on CI or similar label Sep 4, 2020
@mikehardy mikehardy mentioned this pull request Sep 5, 2020
10 tasks
@franciscosolla
Copy link
Contributor Author

Wow, I had forgotten about this haha, sorry. Thank you for fixing it. I'm happy that I could contribute to your project. I use it in every project I develop haha. Awesome work! @mikehardy

androidIsForVivek pushed a commit to androidIsForVivek/react-native-firebase that referenced this pull request Aug 9, 2021
* Updates Firestore Types to Generic Types

Updates firestore types to generic types, as is in the firestore web SDK.
Allows to define specific document data types ensuring type safe operations with collections and documents, plus the convenience of automatic auto-complete from type defined document data.

* Update packages/firestore/lib/index.d.ts

Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
Co-authored-by: Mike Hardy <github@mikehardy.net>
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

Successfully merging this pull request may close these issues.

4 participants