React-native-firebase: Failing flow types in firestore and database

Created on 13 Apr 2018  路  4Comments  路  Source: invertase/react-native-firebase

Issue

Ran flowtype on my project and got following error output for react-native-firebase

null [1] is not an object.
node_modules/react-native-firebase/dist/modules/database/DataSnapshot.js.flow:65:36
65| childKeys: isObject(value) ? Object.keys(value) : [],
^^^^^^^^^^^^^^^^^^
References:
node_modules/react-native-firebase/dist/modules/database/DataSnapshot.js.flow:55:38
55| if (value === undefined) value = null;
^^^^ [1]
Error ------------------------- node_modules/react-native-firebase/dist/modules/firestore/DocumentSnapshot.js.flow:67:20
Cannot call deepGet with this._data bound to object because undefined [1] is incompatible with object type [2].
node_modules/react-native-firebase/dist/modules/firestore/DocumentSnapshot.js.flow:67:20
67| return deepGet(this._data, fieldPath, '.');
^^^^^^^^^^
References:
node_modules/react-native-firebase/dist/modules/firestore/DocumentSnapshot.js.flow:29:19
29| _data: Object | void;
^^^^ [1]
node_modules/react-native-firebase/dist/utils/index.js.flow:24:11
24| object: Object,
^^^^^^ [2]

This is easily fixable by ignoring this in .flowconfig, but wasn't there before, so I figured it might be something worth looking into. This happened after upgrading from v4.0.0 to v4.0.2.

generally when doing things like typeof null it returns "object", I'm not sure what isObject function is in that first error, but perhaps related?

Environment

  1. Application Target Platform:
  1. Development Operating System: macOS High Sierra
  1. Build Tools: XCode 9.3, Android Studio 3.1, Node 9.10.1
  1. React Native version: 0.55.4
  1. RNFirebase Version: 4.0.2
  1. Firebase Module: database, firestore
Bug JavaScript Database Firestore Typings

Most helpful comment

@IljaDaderko it needs to be any as it's referenced in both DocumentSnapshot and DataSnapshot. Whilst in DocumentSnapshot the data is always an Object or null, in DataSnapshot the data can be any

All 4 comments

Thanks for this, this was part of a change in 4.2: https://github.com/invertase/react-native-firebase/commit/f1e9d28869109f45333cff781b592abf3c4d14e1

Will push a fix for it now

Done, if you could test it by replicating the change https://github.com/invertase/react-native-firebase/commit/2a1e3652315f6a1b1f588ed564a1d08a96bf76d8 that'd be great but it should be fine now and will be released as part of v4.0.4

Thanks!

Gotcha, for this change object: any could it be object: Object | null? If it can I could make a pr. @Salakar

@IljaDaderko it needs to be any as it's referenced in both DocumentSnapshot and DataSnapshot. Whilst in DocumentSnapshot the data is always an Object or null, in DataSnapshot the data can be any

Was this page helpful?
0 / 5 - 0 ratings