-
-
Notifications
You must be signed in to change notification settings - Fork 556
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(types): add database and firestore statics #957
feat(types): add database and firestore statics #957
Conversation
Codecov Report
@@ Coverage Diff @@
## master #957 +/- ##
=======================================
Coverage 88.33% 88.33%
=======================================
Files 29 29
Lines 797 797
=======================================
Hits 704 704
Misses 93 93 |
This is awesome, nice work! Do you foresee this causing any issues for folks? It doesn't appear so Asking so we can figure out the version for release |
@prescottprue It should not as it just 'fixes' those few TS issues. The only potential issue I can think of is in regard to not using intersections which doesn't apply here - if there was a property collision, that'd throw a type error if they differed. But as it sits, there are no overlaps here that would cause that kind of issue I can see (and we'd also see that in the build). We could look at introducing some type tests, but being that all this is doing is setting up basic interfaces pointing to the provided Google types, I don't know if that's worth it. If you want to go down that path, I'm open to it and can get a 2nd/3rd opinion as well :) |
@prescottprue Side note: I just quickly scrubbed the APIs for Firebase and compared it what's currently returned by messaging(): firebase.messaging.Messaging;
functions(region?: string): firebase.functions.Functions;
performance(): firebase.performance.Performance;
analytics(): firebase.analytics.Analytics;
remoteConfig(): firebase.remoteConfig.RemoteConfig; If you'd like to chat about any of this, I'm on the Reactiflux discord under the same user name (often found in #redux). I'm happy to contribute more if you're looking for additional help. Thanks! |
Co-authored-by: Chris Serino <[email protected]>
@prescottprue Just updated to handle those scenarios. If you include plugins, they'll automatically be inferred on the instance. Example: import firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";
import "firebase/firestore";
import "@firebase/messaging";
import "@firebase/performance";
import "@firebase/functions";
import "@firebase/analytics";
// import "@firebase/remote-config";
In some component:
const firebase = useFirebase();
console.log('$', firebase.analytics(), firebase.messaging(), '...'); // firebase will have firebase.analytics(), firebase.messaging(), etc..
firebase.remoteConfig() // will throw a type error as it's not imported Thanks to @themindoverall & @phryneas for the help! |
@prescottprue I think this is good to go. Let me know if there's anything else you'd like done here. |
/** | ||
* Firestore instance extended with methods which dispatch | ||
* redux actions. | ||
* @see https://react-redux-firebase.com/docs/api/firebaseInstance.html | ||
*/ | ||
interface ExtendedFirebaseInstance extends DatabaseTypes.FirebaseDatabase { | ||
interface BaseExtendedFirebaseInstance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really like that you combined this all into one it much more clearly matches the name
* feat(types): add database and firestore statics (#957) - @msutkowski, @themindoverall, @phryneas * feat(types): add type predicate to `isLoaded` (#956) - @lukeKonopka * chore(docs): formatting fixes in firestore docs section (#959) - @gregfenton * feat(docs): add firestore populate docs (#954) - @harveychow Co-authored-by: gregfenton <[email protected]> Co-authored-by: Matt Sutkowski <[email protected]> Co-authored-by: Chris Serino <[email protected]> Co-authored-by: Harvey Chow <[email protected]> Co-authored-by: Luke Konopka <[email protected]>
Description
FirebaseDatabaseService
types so that you can achieve:Previously, you would've gotten 'serverTimestamp() is a static member of FieldValue'
useFirestore()
types - previouslywithFirestore
would've been close, butuseFirestore
was missing statics.We've also added inference for plugins, such as performance, analytics, remoteConfig, etc. When a user
import
s those plugins, TS will automatically allow a user to access those properties. This basically works by saying, 'if we see this known key on thefirebase
instance, use the types that we know firebase merged into the namespace'Check List
If not relevant to pull request, check off as complete
Relevant Issues