Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 此reduce函数的类型应该是什么_Javascript_Node.js_Typescript_Lodash - Fatal编程技术网

Javascript 此reduce函数的类型应该是什么

Javascript 此reduce函数的类型应该是什么,javascript,node.js,typescript,lodash,Javascript,Node.js,Typescript,Lodash,我在这里定义了类型[RecordId,any]。但我希望类型是有意义的。我需要将任何类型更改为某种意义上的完整类型 const merged_health_attributes = _.toPairs(sorted_attributes_by_definition_id).reduce((acc,[had_id, v]: [RecordId, any]) => { return acc; }, {}); } 这里是我使用Reals的整个函数,请考虑在这里编辑代码以构成A,如指南中所

我在这里定义了类型[RecordId,any]。但我希望类型是有意义的。我需要将任何类型更改为某种意义上的完整类型

 const merged_health_attributes = _.toPairs(sorted_attributes_by_definition_id).reduce((acc,[had_id, v]: [RecordId, any]) => {
  return acc;
}, {});
}


这里是我使用Reals

的整个函数,请考虑在这里编辑代码以构成A,如指南中所描述的。就目前而言,这里没有足够的信息让我提出任何建议。祝你好运@jcalz我添加了一个洞函数。很抱歉,它依赖于我的IDE中不存在的类型和变量。一个最小的可复制的例子应该只依赖于你实际依赖的东西。。。如果是lodash,那么您应该添加lodash作为标记,以便lodash专家可以帮助您。如果你能找到一些最简单的方法,我也许能帮上忙。否则,祝你好运!
const sorted_attributes_by_definition_id = sorted_health_attributes_to_merge.reduce((acc, attr) => {
  const had_id = attr.relationships.health_attribute_definition.data.id;
  if (!acc[had_id]) {
    // eslint-disable-next-line nurx/no-param-reassign
    acc[had_id] = [];
  }
  acc[had_id].push(attr);
  return acc;
}, {});

// group the attrs for each definition into the format: {recent:HealthAttribute, prev:[HealthAttributes]}
const merged_health_attributes = _.toPairs(sorted_attributes_by_definition_id).reduce((acc,[had_id, v]: [RecordId, any]) => {
  // if the most recent is older than the selected request/renewal by more than a day, don't include it as 'recent'
  // we don't want to old attrs that are time senstitive (like pregnancy, cancer) to come up as 'recent'

  let recent = null;
  let prev = [];
  // if v[0] exists, we want to make sure it's recent enough to display as 'recent'
  if (v[0]) {
    const recent_created_at = moment(v[0].attributes.created_at);
    const source_created_at = moment(request_or_renewal.attributes.created_at);

    // if the source is younger than the attributes by more than a day, don't include them as recent
    if (source_created_at.diff(recent_created_at, 'days') > 1) {
      prev = v;
    } else {
      recent = v[0];
      prev = v.slice(1);
    }
  }

  const to_push = { recent, prev };
  if (!acc[had_id]) {
    // eslint-disable-next-line nurx/no-param-reassign
    acc[had_id] = [];
  }
  acc[had_id].push(to_push);

  return acc;
}, {});

return merged_health_attributes;