What could be the return type of a list of json objects in Angular 2 typescript?

Here What could be the return type of getFiles () (except any), what could be a particular return type?

   @Injectable()
    export class NodeService {

        constructor(private http: Http) {}

        getFiles() {
            return this.http.get('./resources/data/cars-medium.json')
                        .map((res: any) => res.json().data);
        }
    }

cars-medium.json

{
    "data":[
        {"vin":"a1653d4d","brand":"VW","year":1998,"color":"White"},
        {"vin":"ddeb9b10","brand":"Mercedes","year":1985,"color":"Green"},
        {"vin":"d8ebe413","brand":"Jaguar","year":1979,"color":"Silver"},
        {"vin":"aab227b7","brand":"Audi","year":1970,"color":"Black"},
        {"vin":"631f7412","brand":"Volvo","year":1992,"color":"Red"},
        {"vin":"7d2d22b0","brand":"VW","year":1993,"color":"Maroon"}
           ]
}
+4
source share
1 answer
getFiles():Observable<Object[]> {

If you have an interface like

interface Car {
  vin:string;
  brand: string;
  year:number;
  color:string;
}

you can also use

getFiles():Observable<Car[]> {
+4
source

All Articles