diff --git a/dist/bitburner.d.ts b/dist/bitburner.d.ts index 06c6e1445..461c199dc 100644 --- a/dist/bitburner.d.ts +++ b/dist/bitburner.d.ts @@ -3905,7 +3905,7 @@ export declare interface NS extends Singularity { * @param data - Data to write. * @returns True if the data is successfully written to the port, and false otherwise. */ - tryWritePort(port: number, data: string[] | number): Promise; + tryWritePort(port: number, data: string | number): Promise; /** * Read content of a file. diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 339960b55..0fb3758b0 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1841,6 +1841,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }, tryWritePort: function (port: any, data: any = ""): any { updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort")); + if ((typeof data !== "string" && typeof data !== "number") || isNS(data)) { + throw makeRuntimeErrorMsg( + "writePort", + `Trying to write invalid data to a port: only strings and numbers are valid.`, + ); + } if (!isNaN(port)) { port = Math.round(port); if (port < 1 || port > CONSTANTS.NumNetscriptPorts) { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 6e613ba80..e45302614 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5555,7 +5555,7 @@ export interface NS extends Singularity { * @param data - Data to write. * @returns True if the data is successfully written to the port, and false otherwise. */ - tryWritePort(port: number, data: string[] | number): Promise; + tryWritePort(port: number, data: string | number): Promise; /** * Read content of a file.