From e27e89920dede714cff7813f8c965f13bab1e03d Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 16 Apr 2021 15:34:10 +0100 Subject: [PATCH 1/2] fix: give stats initial values Otherwise the compiler cannot derive the type and thinks `stats.snapshot` returns `{}` --- src/metrics/stats.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/metrics/stats.js b/src/metrics/stats.js index 0153624154..1f2f388839 100644 --- a/src/metrics/stats.js +++ b/src/metrics/stats.js @@ -19,7 +19,10 @@ class Stats extends EventEmitter { this._options = options this._queue = [] - this._stats = {} + this._stats = { + dataReceived: Big(0), + dataSent: Big(0) + } this._frequencyLastTime = Date.now() this._frequencyAccumulators = {} From 18204f7098b57b1d6acc05d2fcfd7b8d11280e1a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 16 Apr 2021 15:54:02 +0100 Subject: [PATCH 2/2] fix: add type shape to moving averages as well --- src/metrics/stats.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/metrics/stats.js b/src/metrics/stats.js index 1f2f388839..8d76140031 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,6 +19,8 @@ class Stats extends EventEmitter { this._options = options this._queue = [] + + /** @type {{ dataReceived: Big, dataSent: Big }} */ this._stats = { dataReceived: Big(0), dataSent: Big(0) @@ -27,6 +29,7 @@ class Stats extends EventEmitter { this._frequencyLastTime = Date.now() this._frequencyAccumulators = {} + /** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */ this._movingAverages = {} this._update = this._update.bind(this)