From 3d0a79eff3bc34a5bdc8ffa31e9b09345a02ad9d Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 16 Apr 2021 16:10:22 +0100 Subject: [PATCH] fix: metrics stats and moving averages types (#915) * fix: give stats initial values Otherwise the compiler cannot derive the type and thinks `stats.snapshot` returns `{}` * fix: add type shape to moving averages as well --- src/metrics/stats.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/metrics/stats.js b/src/metrics/stats.js index 01536241..8d761400 100644 --- a/src/metrics/stats.js +++ b/src/metrics/stats.js @@ -2,7 +2,7 @@ 'use strict' const EventEmitter = require('events') -const Big = require('bignumber.js') +const { BigNumber: Big } = require('bignumber.js') const MovingAverage = require('moving-average') const retimer = require('retimer') @@ -19,11 +19,17 @@ class Stats extends EventEmitter { this._options = options this._queue = [] - this._stats = {} + + /** @type {{ dataReceived: Big, dataSent: Big }} */ + this._stats = { + dataReceived: Big(0), + dataSent: Big(0) + } this._frequencyLastTime = Date.now() this._frequencyAccumulators = {} + /** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */ this._movingAverages = {} this._update = this._update.bind(this)