Change Signature of InternalFunction

Mark properties of Wrapped NetscriptAPI as readonly
This commit is contained in:
TheMas3212 2022-04-09 15:15:45 +10:00
parent b2e7817a0b
commit f53c90b21c
No known key found for this signature in database
GPG Key ID: 62A173A4FDA683CA

@ -10,9 +10,7 @@ type ExternalAPI = {
[string: string]: ExternalAPI | ExternalFunction;
};
type InternalFunction<F extends (...args: unknown[]) => unknown> = (
ctx: NetscriptContext,
) => (...args: unknown[]) => ReturnType<F>;
type InternalFunction<F extends (...args: unknown[]) => unknown> = (ctx: NetscriptContext) => F;
export type InternalAPI<API> = {
[Property in keyof API]: API[Property] extends ExternalFunction
? InternalFunction<API[Property]>
@ -23,7 +21,7 @@ export type InternalAPI<API> = {
type WrappedNetscriptFunction = (...args: unknown[]) => unknown;
type WrappedNetscriptAPI = {
[string: string]: WrappedNetscriptAPI | WrappedNetscriptFunction;
readonly [string: string]: WrappedNetscriptAPI | WrappedNetscriptFunction;
};
export type NetscriptContext = {
@ -47,7 +45,6 @@ type NetscriptHelpers = {
};
type WrappedNetscriptHelpers = {
updateDynamicRam: (ramCost: number) => void;
makeRuntimeErrorMsg: (msg: string) => string;
string: (argName: string, v: unknown) => string;
number: (argName: string, v: unknown) => number;
@ -80,7 +77,6 @@ function wrapFunction(
workerScript,
function: functionName,
helper: {
updateDynamicRam: (ramCost: number) => helpers.updateDynamicRam(functionName, ramCost),
makeRuntimeErrorMsg: (msg: string) => helpers.makeRuntimeErrorMsg(functionPath, msg),
string: (argName: string, v: unknown) => helpers.string(functionPath, argName, v),
number: (argName: string, v: unknown) => helpers.number(functionPath, argName, v),