From 4d90414190feb6772c7afe0869dee7636616f4c4 Mon Sep 17 00:00:00 2001 From: Akim <59872966+akim-bow@users.noreply.github.com> Date: Thu, 11 Jan 2024 22:20:08 +0700 Subject: [PATCH] fix(js-client): Remove union with undefined of methods for getting random peer (#417) Fix types --- packages/core/js-client/src/network.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/core/js-client/src/network.ts b/packages/core/js-client/src/network.ts index 42c74f73..ff5c8c5e 100644 --- a/packages/core/js-client/src/network.ts +++ b/packages/core/js-client/src/network.ts @@ -165,21 +165,23 @@ export const kras: Relay[] = [ }, ]; -export const randomKras = () => { +export const randomKras = (): Relay => { return randomItem(kras); }; -export const randomTestNet = () => { +export const randomTestNet = (): Relay => { return randomItem(testNet); }; -export const randomStage = () => { +export const randomStage = (): Relay => { return randomItem(stage); }; -function randomItem(arr: Relay[]) { +function randomItem(arr: Relay[]): Relay { const index = randomInt(0, arr.length); - return arr[index]; + // This array access always defined + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + return arr[index] as Relay; } function randomInt(min: number, max: number) {