From a6afd4ef118832831d5853583980d8aa1f1c2c22 Mon Sep 17 00:00:00 2001 From: Seve Badajoz Date: Mon, 9 Aug 2021 12:20:46 -0700 Subject: [PATCH] type range --- client/src/util/range.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/client/src/util/range.ts b/client/src/util/range.ts index c05f0869..7d78eaf7 100644 --- a/client/src/util/range.ts +++ b/client/src/util/range.ts @@ -22,38 +22,46 @@ rangeFill(array, start, step) -> array */ -// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type. -function _doFill(arr, start, step, count) { +function _doFill( + arr: Array, + start: number, + step: number, + count: number +) { for (let idx = 0, val = start; idx < count; idx += 1, val += step) { arr[idx] = val; } return arr; } -// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type. -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. -export function rangeFill(arr, start = 0, step = 1) { +export function rangeFill( + arr: Array, + start = 0, + step = 1 +): Array { return _doFill(arr, start, step, arr.length); } -// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type. -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. -export function range(start, stop, step) { +export function range( + start: number, + stop?: number, + step?: number +): Array { if (start === undefined) return []; if (stop === undefined) { stop = start; start = 0; } - step = step || 1; // catch undefind and zero + step = step || 1; // catch undefined and zero const len = Math.max(Math.ceil((stop - start) / step), 0); return _doFill(new Array(len), start, step, len); } -// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type. -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. -export function linspace(start, stop, nsteps) { - // @ts-expect-error ts-migrate(2363) FIXME: The right-hand side of an arithmetic operation mus... Remove this comment to see the full error message - const delta = (stop - start) / (nsteps - 1).toFixed(); - // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'i' implicitly has an 'any' type. +export function linspace( + start: number, + stop: number, + nsteps: number +): Array { + const delta = (stop - start) / Number((nsteps - 1).toFixed()); return range(0, nsteps, 1).map((i) => start + i * delta); }