diff --git a/src/Electron.tsx b/src/Electron.tsx index 5fb626794..c0fbe7a0d 100644 --- a/src/Electron.tsx +++ b/src/Electron.tsx @@ -31,7 +31,7 @@ declare global { }; electronBridge: { send: (channel: string, data?: unknown) => void; - receive: (channel: string, func: (...args: any[]) => void) => void; + receive: (channel: string, func: (...args: unknown[]) => void) => void; }; } interface Document { @@ -185,11 +185,14 @@ function initElectronBridge(): void { const data = window.appSaveFns.getSaveData(); bridge.send("get-save-data-response", data); }); - bridge.receive("get-save-info-request", async (save: string) => { + bridge.receive("get-save-info-request", async (save: unknown) => { + if (typeof save !== "string") throw new Error("Error while trying to get save info"); const data = await window.appSaveFns.getSaveInfo(save); bridge.send("get-save-info-response", data); }); - bridge.receive("push-save-request", ({ save, automatic = false }: { save: string; automatic: boolean }) => { + bridge.receive("push-save-request", (params: unknown) => { + if (typeof params !== "object") throw new Error("Error trying to push save request"); + const { save, automatic = false } = params as { save: string; automatic: boolean }; window.appSaveFns.pushSaveData(save, automatic); }); bridge.receive("trigger-save", () => { diff --git a/src/NetscriptFunctions/Flags.ts b/src/NetscriptFunctions/Flags.ts index cd7cf4221..d67158dc0 100644 --- a/src/NetscriptFunctions/Flags.ts +++ b/src/NetscriptFunctions/Flags.ts @@ -1,17 +1,20 @@ import { toNative } from "./toNative"; import libarg from "arg"; +import { ScriptArg } from "../Netscript/ScriptArg"; -export function Flags(vargs: string[]): any { - return () => - (data: any): any => { - data = toNative(data); - // We always want the help flag. +type FlagType = StringConstructor | NumberConstructor | BooleanConstructor | StringConstructor[]; +type FlagsRet = { [key: string]: ScriptArg }; +export function Flags(vargs: string[]): () => (data: unknown) => FlagsRet { + return (/* ctx: NetscriptContext */) => + (schema: unknown): FlagsRet => { + schema = toNative(schema); + if (!Array.isArray(schema)) throw new Error("flags schema passed in is invalid."); const args: { - [key: string]: any; + [key: string]: FlagType; } = {}; - for (const d of data) { - let t: any = String; + for (const d of schema) { + let t: FlagType = String; if (typeof d[1] === "number") { t = Number; } else if (typeof d[1] === "boolean") { @@ -22,8 +25,8 @@ export function Flags(vargs: string[]): any { const numDashes = d[0].length > 1 ? 2 : 1; args["-".repeat(numDashes) + d[0]] = t; } - const ret = libarg(args, { argv: vargs }); - for (const d of data) { + const ret: FlagsRet = libarg(args, { argv: vargs }); + for (const d of schema) { if (!ret.hasOwnProperty("--" + d[0]) || !ret.hasOwnProperty("-" + d[0])) ret[d[0]] = d[1]; } for (const key of Object.keys(ret)) { diff --git a/src/SaveObject.tsx b/src/SaveObject.tsx index bfb0e2033..2bc8999c3 100755 --- a/src/SaveObject.tsx +++ b/src/SaveObject.tsx @@ -49,7 +49,6 @@ export interface SaveData { export interface ImportData { base64: string; - parsed: any; playerData?: ImportPlayerData; } @@ -208,7 +207,6 @@ class BitburnerSaveObject { const data: ImportData = { base64: base64Save, - parsed: parsedSave, }; const importedPlayer = PlayerObject.fromJSON(JSON.parse(parsedSave.data.PlayerSave)); @@ -260,14 +258,19 @@ function evaluateVersionCompatibility(ver: string | number): void { } // The "companyName" property of all Companies is renamed to "name" + interface Company0_41_2 { + name: string | number; + companyName: string; + companyPositions: Record; + } for (const companyName of Object.keys(Companies)) { - const company: any = Companies[companyName]; + const company = Companies[companyName] as unknown as Company0_41_2; if (company.name == 0 && company.companyName != null) { company.name = company.companyName; } if (company.companyPositions instanceof Array) { - const pos: any = {}; + const pos: Record = {}; for (let i = 0; i < company.companyPositions.length; ++i) { pos[company.companyPositions[i]] = true; diff --git a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts index 34e41a236..321eb6983 100644 --- a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts +++ b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts @@ -309,9 +309,9 @@ export async function determineAllPossibilitiesForTabCompletion( return "--" + f[0]; }); try { - return flagFunc(schema); + return flagFunc()(schema); } catch (err) { - return undefined; + return {}; } }, }; diff --git a/src/utils/Validator.ts b/src/utils/Validator.ts index 21afa9198..1e4c47bd9 100644 --- a/src/utils/Validator.ts +++ b/src/utils/Validator.ts @@ -3,7 +3,7 @@ export type ObjectValidator = { }; interface ParameterValidatorObject { - default?: any; + default?: unknown; min?: number; max?: number; func?: (obj: Type, validator: ObjectValidator, key: Key) => void; @@ -26,7 +26,7 @@ export function validateObject, Key extends paramValidator.func(obj, validator, key); } else { if (typeof obj[key] !== typeof paramValidator.default) { - obj[key] = paramValidator.default; + obj[key] = paramValidator.default as Type[Key]; } if (typeof obj[key] === "number" && paramValidator.min !== undefined) { if (obj[key] < paramValidator.min) obj[key] = paramValidator.min as Type[Key];