mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-11 02:03:58 +01:00
added check for NS interface with user defined guard
This commit is contained in:
parent
9ddb1c4379
commit
6ed5a445a8
@ -98,6 +98,11 @@ interface NS extends INS {
|
||||
stanek: IStanek;
|
||||
}
|
||||
|
||||
//interface guard
|
||||
function isNS(object: any): boolean {
|
||||
return (object as NS).gang !== undefined;
|
||||
}
|
||||
|
||||
export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const updateDynamicRam = function (fnName: string, ramCost: number): void {
|
||||
if (workerScript.dynamicLoadedFns[fnName]) {
|
||||
@ -1772,7 +1777,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return res;
|
||||
},
|
||||
writePort: function (port: any, data: any = ""): any {
|
||||
if (typeof data !== "string" && typeof data !== "number") {
|
||||
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.`,
|
||||
|
Loading…
Reference in New Issue
Block a user