I have a json file and I created an interface. But when I did http
request, I do access the data but my typescript compiler is complaining.
"movies": [
{
"title": "Tripple Frontier",
"id": "1",
"actors":[],
"url": "assets/images/netflix-names/220px-Triple_Frontier.jpg",
"producer": "",
"releaseDate": "new Date('24/6/2017')"
},
{
"title":"In the name of the father",
"id": 2,
"actors":[],
"url": "assets/images/netflix- names/In_the_name_of_the_father.jpg",
"producer": "",
"releaseDate": "new Date('15/8/2018')"
}
]
//Model
export interface IMovie {
title: string;
id: number;
actors: [];
url: string;
producer: string;
releaseDate: Date
}
@Injectable()
export class MovieService {
moviesUrl: string = '../assets/movies.json';
constructor(private _http:HttpClient) {
}
getMovies():Observable<IMovie[]> {
return this._http.get(this.moviesUrl).pipe(
map(response => <IMovie[]>response.movies)
)
}
}
Compiler tells me that
property movies does not exist in type object
How can I define the interface so that the typescript compiler will recognize the movies property that is return even though the code runs well ?