I recently encountered a challenge while working on my web project. What are some areas that can be improved?
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {map} from 'rxjs/operators';
import { IMineral } from '../Mineral/IMineral.interface';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class MineralWorldService {
constructor(private http:HttpClient) {
}
getAllMinerals(): Observable<IMineral[]>
{
return this.http.get('data/minerals.json').pipe( map(data=>
{
const mineralsArray: Array<IMineral> =[];
for( const id in data )
{
if(data.hasOwnProperty(id))
{
mineralsArray.push(data[id]);
}
}
return mineralsArray;
}
)
);
}
}
The element is implicitly of type any
due to the fact that a string expression cannot be used to index an Object type. There is no index signature with a parameter of type string
found on type Object
.