Reputation: 880
Im using a forkJoin to do multiple http calls but it give me the error error TS2339: Property 'data' does not exist on type 'Object'
forkJoin(this.userservice.getUser(), this.userservice.getDashboard()).pipe(
map(([userData, dashboardData]) => {
// set the user
this.user = userData;
// set order count
this.orderCount.new = dashboardData.data.new.length;
console.log(dashboardData);
this.dataLoaded = true;
})
).subscribe();
I understand the error because this property comes from a external api so in angular/ionic it is not set. but when i set for example
map(([userData, dashboardData<any>]) => {
or something like that, it does not work. How can i fix this?
the getUser en getDashboard return http objects
getUser() {
return this.http.get(environment.baseUrl + '/auth/user').pipe(
map(results => {
console.log(results);
return results;
})
);
}
Upvotes: 3
Views: 2141
Reputation: 29325
you can type the array like this:
map(([userData, dashboardData]: [UserData, DashboardData]) =>
or you can just type your observables. don't abuse any.
Upvotes: 2
Reputation: 3566
In your code, replace this line
this.orderCount.new = dashboardData.data.new.length;
with this
this.orderCount.new = (dashboardData as any).data.new.length;
What this line does is cast the Object into typescript's any type.
A better way would be to create model classes for data and uses those model class instead of any.
Upvotes: 2