I'm doing a mobile application using:
"dependencies": {
"@react-native-firebase/app": "^6.0.1",
"@react-native-firebase/auth": "^6.0.1",
"@react-native-firebase/firestore": "^6.0.1",
"react": "16.9.0",
"react-native": "0.61.2"
},
"devDependencies": {
"@types/react": "^16.9.9",
"@types/react-native": "^0.60.21",
"typescript": "^3.6.4"
},
Issue
import firestore, {FirebaseFirestoreTypes} from '@react-native-firebase/firestore';
const creationTime: string | undefined = user.user.metadata.creationTime;
const date = new Date(creationTime);
const createdAt: FirebaseFirestoreTypes.Timestamp = firestore.Timestamp.fromDate(date);
While assigning creationTime to date, no overload matches this call.
TS2769: No overload matches this call.
Overload 1 of 4, '(value: string | number | Date): Date', gave the following error.
Argument of type 'string | undefined' is not assignable to parameter of type 'string | number | Date'.
Type 'undefined' is not assignable to type 'string | number | Date'.
Overload 2 of 4, '(value: string | number): Date', gave the following error.
Argument of type 'string | undefined' is not assignable to parameter of type 'string | number'.
Type 'undefined' is not assignable to type 'string | number'.
The data returned from FirebaseAuthTypes.UserCredential has two things, one of them is User, which has a UserMetadata and inside of it we have creationTime?: string;. For some reason the IDE thinks it's string | undefined. Why it would be undefined if the user is already signed up? Maybe I'm missing something or there is a Type bug?
Also, doing this brings me error too:
const creationTime: string = user.user.metadata.creationTime;
TS2322: Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
Just to mention and compare, the official documentation says that creationTime only returns string:
https://firebase.google.com/docs/reference/node/firebase.auth.UserMetadata
In the meanwhile, I have solved this using:
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const creationTime: Date = new Date(user.user.metadata.creationTime);
Environment
Click To Expand
react-native info output:
System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 310.58 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.16.3 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
Android SDK:
API Levels: 21, 25, 26, 27, 28
Build Tools: 27.0.3, 28.0.2, 28.0.3
System Images: android-21 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5900203
Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-rename: 2.4.1
- Platform that you're experiencing the issue on:
react-native-firebase version you're using that has this issue:
Firebase module(s) you're using that has the issue:
@react-native-firebase/auth
@react-native-firebase/firestore
- Are you using
TypeScript?
I'm doing a mobile application using:
Issue
While assigning
creationTimetodate, no overload matches this call.The data returned from
FirebaseAuthTypes.UserCredentialhas two things, one of them isUser, which has aUserMetadataand inside of it we havecreationTime?: string;. For some reason the IDE thinks it'sstring | undefined. Why it would beundefinedif the user is already signed up? Maybe I'm missing something or there is a Type bug?Also, doing this brings me error too:
Just to mention and compare, the official documentation says that
creationTimeonly returnsstring:https://firebase.google.com/docs/reference/node/firebase.auth.UserMetadata
In the meanwhile, I have solved this using:
Environment
Click To Expand
react-native infooutput:react-native-firebaseversion you're using that has this issue:6.0.1Firebasemodule(s) you're using that has the issue:@react-native-firebase/auth@react-native-firebase/firestoreTypeScript?Y&3.6.4