score:0

the problem here is that rawlistitemcachevalue[list] is not the same as listdatamap[list][], even though it really looks like it is.

if you check the error you will see whats the difference is in that line: commentdata | devicedata | userdata is not assignable to type commentdata.

what this means is that when yo do this:

type rawlistitemcachevalue = {
  // [name of list]: array of list items
  [list in listname]?: listdatamap[list][];
};

somehow you are telling tsc this:

type rawlistitemcachevalue = {
  [commentdata]?: listdatamap[commentdata][];
  [devicedata]?: listdatamap[devicedata][];
  {...}
};

so the key and the value are correlated.

the problem is that when you do listdatamap[list][] with list being === to keyof listname, this value can be anyone on listdatamap. so when you do listitemcache[list] = items; you are really doing:

listitemcache['commentdata' | 'devicedata' | 'userdata'] = (commentdata | devicedata | userdata)[]

so tsc complains for that because listitemcache['commentdata'] = devicedata would be a possible combination which is wrong.


Related Query

More Query from same tag