我想找到一种方法,如何将不同的对象传递给同一个函数,并让该函数仅处理给定对象中存在的输入。具体来说,我传递不同的角度组件,并解构对象属性。
export function filterVisualData({data, playersOn, typesOn, resultsOn, toBeRemoved, teamsOn, xGOn, shotsOn}) {
return data.filter(d => {
const result = d.success ? 'Successful' : 'Unsuccessful';
const players = playersOn.length === 0 || (playersOn.length > 0 && playersOn.includes(d.player_name));
const types = typesOn.length === 0 || (typesOn.length > 0 && typesOn.includes(capitalizeAllWords(d.type)));
const results = resultsOn.length === 0 || (resultsOn.length > 0 && resultsOn.includes(result));
const removed = !toBeRemoved.map(p => p.time).includes(d.time);
const shots = shotsOn.length === 0 || (shotsOn.length > 0 && shotsOn.includes(d.type));
const xG = xGOn.length === 0 || (xGOn.length > 0 && d.xG < Math.max(...xGOn));
const teams = teamsOn.length === 0 || (teamsOn.length > 0 && teamsOn.includes(d.team_name));
return players && types && results && removed && shots && xG && teams;
});
}
问题是某些组件缺少某些属性,我收到此错误
TS2345:“this”类型的参数不可分配给“{ data: any;”类型的参数 玩家:任何;类型:任意;结果:任意;待删除:任何;团队:任何;xGOn:任意;开枪:任意;}'。类型“ShotChart”不可分配给类型“{ data: any; 玩家:任何;类型:任意;结果:任意;待删除:任何;团队:任何;xGOn:任意;开枪:任意;}'。类型“ShotChart”中缺少属性“typesOn”。
海绵宝宝撒
慕侠2389804
相关分类