From c9432e4cd7a4fe89769c5ea45b7c0aa84bcff044 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 14 Jul 2022 21:54:49 -0400 Subject: [PATCH] rm any --- src/Gang/Gang.ts | 6 +++--- src/utils/helpers/arrayToString.ts | 6 +++--- src/utils/helpers/exceptionAlert.ts | 12 ++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Gang/Gang.ts b/src/Gang/Gang.ts index ecca414f5..7c0d3515f 100644 --- a/src/Gang/Gang.ts +++ b/src/Gang/Gang.ts @@ -10,7 +10,7 @@ import { Factions } from "../Faction/Factions"; import { dialogBoxCreate } from "../ui/React/DialogBox"; import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver"; -import { exceptionAlert } from "../utils/helpers/exceptionAlert"; +import { exceptionAlert, isIError } from "../utils/helpers/exceptionAlert"; import { getRandomInt } from "../utils/helpers/getRandomInt"; import { GangMemberUpgrade } from "./GangMemberUpgrade"; @@ -99,7 +99,7 @@ export class Gang implements IGang { this.processExperienceGains(cycles); this.processTerritoryAndPowerGains(cycles); this.storedCycles -= cycles; - } catch (e: any) { + } catch (e: unknown) { console.error(`Exception caught when processing Gang: ${e}`); } } @@ -358,7 +358,7 @@ export class Gang implements IGang { workerScript.log("gang.ascendMember", () => `Ascended Gang member ${member.name}`); } return res; - } catch (e: any) { + } catch (e: unknown) { if (workerScript == null) { exceptionAlert(e); } diff --git a/src/utils/helpers/arrayToString.ts b/src/utils/helpers/arrayToString.ts index 405adb216..68b4a39c7 100644 --- a/src/utils/helpers/arrayToString.ts +++ b/src/utils/helpers/arrayToString.ts @@ -5,10 +5,10 @@ * - Adds brackets around the array * - Adds quotation marks around strings */ -export function arrayToString(a: T[]): string { - const vals: any[] = []; +export function arrayToString(a: unknown[]): string { + const vals: unknown[] = []; for (let i = 0; i < a.length; ++i) { - let elem: any = a[i]; + let elem: unknown = a[i]; if (Array.isArray(elem)) { elem = arrayToString(elem); } else if (typeof elem === "string") { diff --git a/src/utils/helpers/exceptionAlert.ts b/src/utils/helpers/exceptionAlert.ts index c466cfd6f..b3264ef9e 100644 --- a/src/utils/helpers/exceptionAlert.ts +++ b/src/utils/helpers/exceptionAlert.ts @@ -5,17 +5,21 @@ interface IError { lineNumber?: number; } -export function exceptionAlert(e: IError | string): void { +export const isIError = (v: unknown): v is IError => { + if (typeof v !== "object" || v == null) return false; + return v.hasOwnProperty("fileName") && v.hasOwnProperty("lineNumber"); +}; + +export function exceptionAlert(e: unknown): void { console.error(e); let msg = ""; let file = "UNKNOWN FILE NAME"; let line = "UNKNOWN LINE NUMBER"; - const isError = (e: IError | string): e is IError => e.hasOwnProperty("fileName"); - if (isError(e)) { + if (isIError(e)) { file = e.fileName ?? file; line = e.lineNumber?.toString() ?? line; } else { - msg = e; + msg = String(e); } dialogBoxCreate( "Caught an exception: " +