My current project involves working with GCP and Firebase using typescript. I have been utilizing the provided libraries, specifically version 8 of Firebase, and have encountered some unexpected behavior.
For instance (firebase, ver. 8.10.1)
import 'firebase/auth'
import firebase from 'firebase/app'
firebase.initializeApp({ apiKey: 'my-api-key', projectId: 'my-project-id' })
const auth = firebase.auth()
const { user } = await auth.signInWithEmailAndPassword('example@example.com', 'example-password')
signInWithEmailAndPassword
method returns an object of type UserCredential
with properties typed as Type | null
type UserCredential = {
additionalUserInfo?: firebase.auth.AdditionalUserInfo | null;
credential: firebase.auth.AuthCredential | null;
operationType?: string | null;
user: firebase.User | null;
};
I've noticed that there are instances where these methods return a null
value. However, based on my testing, they generally either return valid values or reject the promise with an error. I haven't found any documentation explaining why null
may be returned.
A similar scenario with other libraries (secret-manager, ver. 4.2.0)
import { SecretManagerServiceClient } from '@google-cloud/secret-manager'
const secretManager = new SecretManagerServiceClient()
const [secretVersion] = await secretManager.accessSecretVersion({
name: 'projects/p/secrets/secret-name/versions/latest'
})
In this case as well, the return type includes:
interface IAccessSecretVersionResponse {
name?: string | null;
payload?: google.cloud.secretmanager.v1.ISecretPayload | null;
}
I'm curious about the origin of these null
values. When could these libraries potentially return null
instead of an error? Can anyone provide insights on this behavior or direct me to relevant documentation?