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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -