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

Typescript not working on firebase. unless used as firebase.app(). #774

Closed
xzilja opened this issue Jan 23, 2018 · 13 comments · Fixed by #788
Closed

Typescript not working on firebase. unless used as firebase.app(). #774

xzilja opened this issue Jan 23, 2018 · 13 comments · Fixed by #788
Labels
tools: typings TypeScript / Flow

Comments

@xzilja
Copy link
Contributor

xzilja commented Jan 23, 2018

Issue

I was using firebase.app().auth previously until discovering that app() bit is no longer needed. Switching to firebase.auth causes typescript error below (not only for auth, but in general)

example

[ts] Property 'auth' does not exist on type 'typeof FireBase'.
any

Environment

  1. Application Target Platform: iOS, Android
  1. Development Operating System: macOS High Sierra
  1. Build Tools:
  1. React Native version: 0.52
  1. RNFirebase Version: 3.2.1
  1. Firebase Module:
@Ehesp
Copy link
Member

Ehesp commented Jan 23, 2018

@iljadaderko does this happen on the other modules as well?

@xzilja
Copy link
Contributor Author

xzilja commented Jan 23, 2018

@Ehesp indeed it does, judging by typescript suggestions a lot is missing, see screenshots for both firebase. and firebase.app(). below (everything seems to be typed correctly for app())

firebase

firebase.app()

@Ehesp
Copy link
Member

Ehesp commented Jan 24, 2018

@pheromonez do you mind taking a look at this issue?

@pheromonez
Copy link
Contributor

@Ehesp No problem, I'll submit a PR once I've got something ready

@Ehesp
Copy link
Member

Ehesp commented Jan 24, 2018

Awesome thanks very much!

@chrisbianca chrisbianca added the tools: typings TypeScript / Flow label Jan 26, 2018
@d4l-w4r
Copy link
Contributor

d4l-w4r commented Jan 26, 2018

What works for me is to first instantiate a firebase object (for example in an injection container like TSDI) const firebase = new FireBase().
And then use the modules on that instance like firebase.auth(), firebase.links(), etc.
I always assumed that was intended behavior 😅

@xzilja
Copy link
Contributor Author

xzilja commented Jan 26, 2018

@danielw93 That did the trick for me, but docs show implementation that is more concise with web sdk: https://rnfirebase.io/docs/v3.2.x/installation/javascript in my opinion this is more friendly to web devs coming into react-native-firebase.

@meyer
Copy link

meyer commented Jan 27, 2018

firestore also seems to be missing from type defs. I tried the new Firebase approach that @danielw93 suggested but got errors saying that Firebase is not a constructor. I’ve resorted to commonjs imports to skip type checking, which is definitely less than ideal:

import firebase from 'react-native-firebase';
const firebase2 = require('react-native-firebase');

// ...

firebase.app().auth().signInAnonymously().then(user => {
  const docRef = firebase2.default.firestore().collection('users').doc(user.uid);
  // ...
});

@pheromonez let me know if there’s anything I can do to help with fixing type definitions.

I dug around a bit to see if I could find a flow to .d.ts generator, but didn’t have a lot of luck. Seems like this should be an automated thing.

@Ehesp
Copy link
Member

Ehesp commented Jan 28, 2018

@meyer there's currently a PR for Firestore

@pheromonez
Copy link
Contributor

@Ehesp I've submitted a PR to improve the TS definitions. While going through the JS code I noticed that there's a utils package which is undocumented on https://rnfirebase.io/. Is this package intended for internal use only?

@meyer Thanks for the offer to help. This fix was fairly small, so I've been able to complete it, but there are a couple of modules that currently don't have any TS definitions (admob, config, perf) and could certainly use some attention.

@Ehesp
Copy link
Member

Ehesp commented Jan 29, 2018

@pheromonez yeah the utils directory is used for things like internal event emitters, common helpers and the like and isn't designed for public consumption.

@Ehesp
Copy link
Member

Ehesp commented Jan 30, 2018

Closing in favour of #788

@Ehesp Ehesp closed this as completed Jan 30, 2018
@eazeye
Copy link

eazeye commented Mar 20, 2019

This may not be the right place, but I'm wondering what the rationale for returning multiple values was?
For example, calling firestore.data() will return the following:

Screen Shot 2019-03-20 at 12 42 30 PM

For Javascript it doesn't seem to matter, but for Typescript I've had to structure my code differently in comparison to if I was just using that standard Firebase.firestore SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools: typings TypeScript / Flow
Projects
None yet
7 participants