Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions static/app/stores/groupStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,19 @@ const storeConfig: GroupStoreDefinition = {
},

mergeItems(items: Item[]) {
const itemsById = items.reduce((acc, item) => ({...acc, [item.id]: item}), {});
const itemsById: Record<string, Item> = items.reduce((acc, item) => {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
acc[item.id] = item;
return acc;
}, {});
Comment on lines +153 to +157
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick follow up:

we don’t need the ts-expect-error if we “type” reduce itself


// Merge these items into the store and return a mapping of any that aren't already in the store
this.items.forEach((item, itemIndex) => {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
if (itemsById[item.id]) {
this.items[itemIndex] = {
...item,
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
...itemsById[item.id],
};
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
delete itemsById[item.id];
}
});
Expand All @@ -188,9 +189,12 @@ const storeConfig: GroupStoreDefinition = {
*/
addToFront(items) {
items = toArray(items);
const itemMap = items.reduce((acc, item) => ({...acc, [item.id]: item}), {});
const itemMap: Record<string, Item> = items.reduce((acc, item) => {
// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
acc[item.id] = item;
return acc;
}, {});

// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
this.items = [...items, ...this.items.filter(item => !itemMap[item.id])];

this.updateItems(items.map(item => item.id));
Expand Down Expand Up @@ -484,10 +488,10 @@ const storeConfig: GroupStoreDefinition = {

onPopulateStats(itemIds, response) {
// Organize stats by id
const groupStatsMap = response.reduce<Record<string, GroupStats>>(
(map, stats) => ({...map, [stats.id]: stats}),
{}
);
const groupStatsMap = response.reduce<Record<string, GroupStats>>((map, stats) => {
map[stats.id] = stats;
return map;
}, {});

this.items.forEach((item, idx) => {
if (itemIds?.includes(item.id)) {
Expand Down
Loading