From 3bf9c38dd9011656ed0d55f55dec42093a1b43f0 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 18 Feb 2020 15:01:22 -0700 Subject: [PATCH] Set original array type passed into the function to array of ILayerTypeCount. Set return type on reduce function --- .../server/maps_telemetry/maps_telemetry.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts index 7bd8bde9e14d7e..4a7297d5810efd 100644 --- a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -22,16 +22,23 @@ interface Stats { }; } -function getUniqueLayerCounts(layerCountsList: object[], mapsCount: number) { +interface ILayerTypeCount { + [key: string]: number; +} + +function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: number) { const uniqueLayerTypes = _.uniq(_.flatten(layerCountsList.map(lTypes => Object.keys(lTypes)))); return uniqueLayerTypes.reduce((accu: Stats, type: string) => { - const typeCounts = layerCountsList.reduce((tCountsAccu: number[], tCounts: any) => { - if (tCounts[type]) { - tCountsAccu.push(tCounts[type]); - } - return tCountsAccu; - }, []); + const typeCounts = layerCountsList.reduce( + (tCountsAccu: number[], tCounts: ILayerTypeCount): number[] => { + if (tCounts[type]) { + tCountsAccu.push(tCounts[type]); + } + return tCountsAccu; + }, + [] + ); const typeCountsSum = _.sum(typeCounts); accu[type] = { min: typeCounts.length ? _.min(typeCounts) : 0,