Skip to content

Specify the return document type for AngularFirestoreDocument.get() #2361

Closed

Description

@zer09

The return type of the AngularFirestoreDocument.get() is not set, this will cause the editor cant perform autocomplete when calling DocumentSnapshot.data() because it will just treat its return type, as firestore.DocumentData instead the real type.

Version info

Angular: 9.0.7

Firebase: 7.11.0

AngularFire: 5.4.2

Other (e.g. Ionic/Cordova, Node, browser, operating system):
Node: v12.6
npm: 6.14.2
Browser: Latest chrome and firefox nightly.

How to reproduce these conditions

export class Sample {
  constructor(private afStore AngularFirestore) {}
  
  test(path: string)  {
    this.afStore.doc<SampleType>(path).get().pipe(take(1)).subscribe(doc => {
      console.log(doc.data()); // The real type of doc.data() is not infered by the editor.
    })
  }
}

Expected behavior

personalinfo

The return type should be

Observable<firebase.firestore.DocumentSnapshot<firebase.firestore.SamlpeType>>

This will allow to infer the type of the doc.data()

Actual behavior

documentdata

The return type is

Observable<firebase.firestore.DocumentSnapshot<firebase.firestore.DocumentData>>

With this the autocomplete will not work

Possible Solution

Based on index.d.ts on firestore, it is implemented like this.

export class DocumentSnapshot<T = DocumentData> {
  data(options?: SnapshotOptions): T | undefined;
}

I think setting the return type of get on document.ts to

get(options?: firestore.GetOptions): Observable<firestore.DocumentSnapshot<T>>

will fix the issue.

Activity

  1. KingDarBoja commented on Jun 30, 2020

    @KingDarBoja
    Contributor

    The return type should be indeed a generic as the other methods inside the AngularFirestoreDocument class definition.

  2. jamesdaniels commented on Nov 12, 2020

    @jamesdaniels
    Contributor

    Should be addressed in 6.1.0-rc.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions