The way I would write is like this:
interface IRestaurant {
restaurant_id: number;
restaurant_rank: number;
restaurant_details?: any;
}
interface IThing {
user_id: number;
timestamp: string;
restaurants: Array<IRestaurant>;
}
const test: IThing = {
user_id: 5,
restaurants: [
{
restaurant_id: 5,
restaurant_rank: 5
},
{
restaurant_id: 6,
restaurant_rank: 6
}
],
timestamp: 'test'
};
There is a few other ways you can do the array:
interface IThing {
user_id: number;
timestamp: string;
restaurants: IRestaurant[];
}
interface IThing {
user_id: number;
timestamp: string;
restaurants: Array<{restaurant_id: number, restaurant_rank: number}>;
}
I noticed in your replied answer you do restaurant_details: Object
. You should do restaurant_details: any
because Object is more restrictive than any. See https://stackoverflow.com/a/18961904/2592233
I also add a question mark after restaurant_details
to tell the compiler this is optional since you didn't have in the first example.