firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

[FR]: Why FirestoreDataConverter does not have two generics?

Open dar0xt opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Add new generics type for fromFirestore in FirestoreDataConverter.

Describe the solution you'd like

Hi, I have suggestion about type of FirestoreDataConverter. Although QueryDocumentSnapshot has generics type, FirestoreDataConverter has no generics except T. Colud you add generics type S for QueryDocumentSnapshot in "fromFirestore" ?

export interface FirestoreDataConverter<T> {
    /**
     * Called by the Firestore SDK to convert a custom model object of type T
     * into a plain Javascript object (suitable for writing directly to the
     * Firestore database). To use set() with `merge` and `mergeFields`,
     * toFirestore() must be defined with `Partial<T>`.
     *
     * The `WithFieldValue<T>` type extends `T` to also allow FieldValues such
     * as `FieldValue.delete()` to be used as property values.
     */
    toFirestore(modelObject: WithFieldValue<T>): DocumentData;

    /**
     * Called by the Firestore SDK to convert a custom model object of type T
     * into a plain Javascript object (suitable for writing directly to the
     * Firestore database). To use set() with `merge` and `mergeFields`,
     * toFirestore() must be defined with `Partial<T>`.
     *
     * The `PartialWithFieldValue<T>` type extends `Partial<T>` to allow
     * FieldValues such as `FieldValue.delete()` to be used as property values.
     * It also supports nested `Partial` by allowing nested fields to be
     * omitted.
     */
    toFirestore(
      modelObject: PartialWithFieldValue<T>,
      options: SetOptions
    ): DocumentData;

    /**
     * Called by the Firestore SDK to convert Firestore data into an object of
     * type T.
     */
    fromFirestore(snapshot: QueryDocumentSnapshot): T;
  }
  export class QueryDocumentSnapshot<
    T = DocumentData
  > extends DocumentSnapshot<T> {
    private constructor();

    /**
     * The time the document was created.
     */
    readonly createTime: Timestamp;

    /**
     * The time the document was last updated (at the time the snapshot was
     * generated).
     */
    readonly updateTime: Timestamp;

    /**
     * Retrieves all fields in the document as an Object.
     *
     * @override
     * @return An Object containing all fields in the document.
     */
    data(): T;
  }

dar0xt avatar May 25 '23 01:05 dar0xt