javascript - How can I specify an array of objects indexed by a field in Typescript? -


i have got far:

testquestions: {     data: [{ admintestid: number,              admintestquestionid: number,              questionuid: string,              subtopidid: number,              title: string }] }; 

now add in object called datamap. object result of passing data through reduce function:

 testquestions.datamap = data.reduce((rv, v) => {             rv[v.questionuid] = v;             return rv;         }, {}); 

can telling me how can define (inline) datamap?

testquestions: {     data: [{ admintestid: number,              admintestquestionid: number,              questionuid: string,              subtopidid: number,              title: string }],    datamap: questionuid: string [{ admintestid: number,              admintestquestionid: number,              questionuid: string,              subtopidid: number,              title: string }] 

};

i have tried above it's not correct. hope can here.

you close. first lets break out object type own interface clarity.

interface question {     admintestid: number;      admintestquestionid: number;      questionuid: string;      subtopidid: number;      title: string; } 

this syntax looking in datamap.

interface questionmap {     [questionuid: string]: question; } 

all together.

interface testquestions {      data: question[];     datamap: questionmap; }  var testquestions: testquestions = {     data: [],     datamap: {}, }; 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -