Using Javascript with Typescript (v1.4.1) I have a custom type as follows:
interface WordDataForQuestion {
question : {
id : number;
vocab : string;
comment : string;
};
possibleAnswers : {
[index : number] : {
id : number;
vocab : string;
comment : string;
}
};
}
Now I want to push an element in the array possibleAnswers
nextWordData.possibleAnswers.push(
{
id : vocabs[index].id,
vocab : vocabs[index].voc_t,
comment : vocabs[index].com_t
}
);
but it gives me the following error:
exercise.ts(69,42): error TS2339: Property 'push' does not exist on type '{ [index: number]: { id: number; vocab: string; comment: string; }; }'.
I don't understand what is wrong - possibleAnswers
should be a JavaScript array here which supports the push-operation. Am I not right?