Search code examples
typescriptfirebaseionic3angularfire2angularfire

Typescript Error Property 'members' does not exist on type '{}'


This piece of code has been working well until a few days ago when I upgraded angularfire and firebase: From "angularfire2": "5.0.0-rc.4", to "angularfire2": "^5.1.0", from "firebase": "4.8.0", to "firebase": "^5.5.7":

this.dataProvider.getGroup(this.groupId).snapshotChanges().subscribe((group) => {
  this.group = group.payload.val();
  this.groupMembers = null;
  // Get group members
  if (group.payload.val().members) {
    group.payload.val().members.forEach((memberId) => {
      this.dataProvider.getUser(memberId).snapshotChanges().subscribe((member) => {
        this.addOrUpdateMember(member);
      });
    });
    // Get user's contacts to add
    this.dataProvider.getCurrentUser().snapshotChanges().subscribe((account) => {
      if (account.payload.val().contacts) {

        //Delete log
        console.log('My contacts',account.payload.val().contacts);
        for (var i = 0; i < account.payload.val().contacts.length; i++) {
          this.dataProvider.getUser(account.payload.val().contacts[i]).snapshotChanges().subscribe((contact) => {
            // Only contacts that are not yet a member of this group can be added.

              contact = { $key: contact.key, ...contact.payload.val()};
              //Delete log
              console.log('Is contact',contact,' already added?',this.isMember(contact));
            if (!this.isMember(contact))
              this.addOrUpdateContact(contact);
          });
        }
        if (!this.contacts) {
          this.contacts = [];
        }
      } else {
        this.contacts = [];
      }
    });
  }
  this.loadingProvider.hide();
});

This is the getGroup() in the provider:

getGroup(groupId) {
    return this.angularfire.object('/groups/' + groupId);
}

It is bringing this error everywhere there is payload.val().someProperty in the project.


Solution

  • This is what I had to do to get it working:

    this.dataProvider.getGroup(this.groupId).snapshotChanges().subscribe((group) => {
      let data: any = group.payload.val();
      if (data.members) {   
          /* do something */
      }
    

    So apparently I had to include : any. Again, given that is was working before I made the upgrade - the experts will tell us more of the cause.