Search code examples
javascriptangularfirebasefirebase-realtime-databaseangularfire2

How to solve Angular data service function error?


I want to get data from my firebase real time db with the following function:

  getTasks() {
    if ( this.orgId === this.db.list(`users/${this.uId}/organization`) ) {
      this.db.list(`users/${this.uId}/product_views`);
    } else
    return;
  }

But VS Code shows me this error: This condition will always return 'false' since the types 'string' and 'AngularFireList' have no overlap.ts(2367)

Unfortunately I am completely new to JS or TS and have no idea how to fix it.


Solution

  • Typecast your if condition:

    getTasks() {
      if ( String(this.orgId) === String(this.db.list(`users/${this.uId}/organization`)) ) {
        this.db.list(`users/${this.uId}/product_views`);
      } else
      return;
    }
    

    or change '===' with '==';

    getTasks() {
      if ( this.orgId == this.db.list(`users/${this.uId}/organization`) ) {
        this.db.list(`users/${this.uId}/product_views`);
      } else
      return;
    }