Getting this error please tell me how to resolve this thank you.
getClients(): Observable<Client[]> {
// get clients with id
this.clients = this.clientsCollection.snapshotChanges().map(changes => {
return changes.map(action => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
CodePudding user response:
Seems you run your angular project on strict you have couple of options.
Better practice is to get use to strict mode that can save you a lot of headache down the road, although some times it will cause the headache it self but trust me its worth it in the long run.
- In your case add
:anybefore:
getClients(): Observable<Client[]> {
// get clients with id
this.clients = this.clientsCollection.snapshotChanges().map(changes:any => {
return changes.map(action:any => {
const data = action.payload.doc.data() as Client;
data.id = action.payload.doc.id;
return data;
});
});
return this.clients;
}
In your
tsconfig.jsonadd this"noImplicitAny": falseto"compilerOptions":{}this will cancel the alerts from the compiler.Create interface of the right type and work with it. this way the compiler can correct you if needed and prevent you making mistakes or trying to access a null ref.
best practice is option 3 but not always its right or worth building the interface just take it into consideration. And try to avoid :any when ever you can.
CodePudding user response:
Try changing the code to:
snapshotChanges().map((changes:any) => {...})
and
returns changes.map((action: any) ...

