typefix netscriptFunctions (see desc)

* Types for InternalFunction and ExternalFunction have been modified to actually typecheck ns functions against docs.
* Internal functions are required to use unknown for any params on the inner function.
* Return types for internal function inner-function must match the respective external function.
* Added new typecheck assertion function for asserting dynamic object types, to allow unknownifying params that were previously hardcoded objec structures.
* Because type assertion for parameter types and return types is enforced by InternalAPI, removed all duplicate type declarations on NetscriptFunction params and returns.
This commit is contained in:
omuretsu
2022-10-12 08:49:27 -04:00
parent 41b6f0b87b
commit 7a384d53f4
20 changed files with 2845 additions and 3271 deletions
+6 -12
View File
@@ -1,8 +1,4 @@
import {
Infiltration as IInfiltration,
InfiltrationLocation,
PossibleInfiltrationLocation,
} from "../ScriptEditor/NetscriptDefinitions";
import { Infiltration as IInfiltration, InfiltrationLocation } from "../ScriptEditor/NetscriptDefinitions";
import { Location } from "../Locations/Location";
import { Locations } from "../Locations/Locations";
import { calculateDifficulty, calculateReward } from "../Infiltration/formulas/game";
@@ -44,17 +40,15 @@ export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
};
};
return {
getPossibleLocations: () => (): PossibleInfiltrationLocation[] => {
getPossibleLocations: () => () => {
return getLocationsWithInfiltrations.map((l) => ({
city: l.city ?? "",
name: String(l.name),
}));
},
getInfiltration:
(ctx: NetscriptContext) =>
(_location: unknown): InfiltrationLocation => {
const location = helpers.string(ctx, "location", _location);
return calculateInfiltrationData(ctx, location);
},
getInfiltration: (ctx) => (_location) => {
const location = helpers.string(ctx, "location", _location);
return calculateInfiltrationData(ctx, location);
},
};
}