Skip to content

DocumentSnapshot.exists has incosistency in firebase and firebase-admin packages #7141

@ArturAmpilogov

Description

@ArturAmpilogov

Describe your environment

  • Operating System version: Debian 11
  • Browser version: Chrome 111.0.5563.64
  • Firebase SDK version:
    • firebase: 9.16.0
    • firebase-admin: 11.5.0
  • Firebase Product: database (firestore)

Describe the problem

There are two NPM packages: firebase, which is mostly used in Web frontend applications, and firebase-admin, which is usually used in backend NodeJS functions.

  1. The firebase package is using @firebase/firestore, which has the next code for DocumentSnapshot:
export declare class DocumentSnapshot<T = DocumentData> {
     /**
     * Returns whether or not the data exists. True if the document exists.
     */
    exists(): this is QueryDocumentSnapshot<T>;
}
  1. The firebase-admin package is using @google/cloud, which has the next code for DocumentSnapshot:
 export class DocumentSnapshot<T = DocumentData> {

    /** True if the document exists. */
    readonly exists: boolean;

In the first case exists field is a function, while in the second case it is a boolean field.

It would be nice to have some API consistency for the both cases. It will also simplify a bit helper classes writing, currently it requires checks for a field type to make a switch.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions