I encountered an issue while setting up the http connection in my Angular 7 system. The error message popped up when I tried to make a get request:
Type 'Promise<any>' is missing the following properties from type 'User': id, user, email
Here is the relevant code snippet:
export class User {
id: number,
user: string,
email: string
}
This is how the request was handled:
users: User;
this.userService.getUsers().subscribe(
response => {
if (!response) {
console.log(Error)
} else {
this.users = response
}
})
The Http Get method looks like this:
getUsers() {
return this.service.get(this.endpoint)
.map((response) => {
return response;
});
}
When it comes to the service, here's what is implemented:
standardHeaders() {
const headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
if (this.authToken) {
headers.append('X-Authorization', this.authToken);
}
return { headers: headers };
}
get(path: string) {
return this.http.get(this.url + path, this.standardHeaders()).map((response: Response) => {
return response.json();
});
}
path = endpoint