Skip to content

Commit 3d0a79e

Browse files
authored
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
1 parent 55ee332 commit 3d0a79e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/metrics/stats.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict'
33

44
const EventEmitter = require('events')
5-
const Big = require('bignumber.js')
5+
const { BigNumber: Big } = require('bignumber.js')
66
const MovingAverage = require('moving-average')
77
const retimer = require('retimer')
88

@@ -19,11 +19,17 @@ class Stats extends EventEmitter {
1919

2020
this._options = options
2121
this._queue = []
22-
this._stats = {}
22+
23+
/** @type {{ dataReceived: Big, dataSent: Big }} */
24+
this._stats = {
25+
dataReceived: Big(0),
26+
dataSent: Big(0)
27+
}
2328

2429
this._frequencyLastTime = Date.now()
2530
this._frequencyAccumulators = {}
2631

32+
/** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */
2733
this._movingAverages = {}
2834

2935
this._update = this._update.bind(this)

0 commit comments

Comments
 (0)