To declare an array, the following two syntaxes are valid: if you are looking for an option that avoids using an interface:
contentOrderBy: { id: number, name: string, key: string }[];
or
contentOrderBy: Array<{ id: number, name: string, key: string }>;
Then fill the array as in the OP question.
Since I found this question when looking for the right way to define an array inside an object, I will also add this example. In this example, the "key" property of an object is an array of strings.
contentOrderBy: { id: number, name: string, key: string[] }[];
or
contentOrderBy: Array<{ id: number, name: string, key: Array<string> }>;
source share