Reputation: 89
I'm a beginner to angular and am taking an online course on edx. In one of the tutorial labs, I am learning how to use the HttpClient
.
ngOnInit() {
this.GitSearchService.gitSearch('angular').then( (response) => {
alert("Total Libraries Found:" + response.total_count);
}, (error) => {
alert("Error: " + error.statusText)
})
}
title = 'app is functional!';
}
It says total_count
does not exist on type unknown, but in one of the imports, I have "total_count": number
Upvotes: 0
Views: 173
Reputation: 6255
Problem is that the response
variable doesn't have a type.
You can fix that in different ways, some cleaner, some less.
An unclean way, for example, would be to workaround the typing
alert("Total Libraries Found:" + response['total_count']);
A more clean way would be to provide a type to the response
this.GitSearchService.gitSearch('angular')
.then( (response : MyAwesomeType) => { your code } )
in this case, MyAwesomeType
is expected to be a type that has the property total_count
Upvotes: 2