mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 08:13:50 +02:00
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:
@@ -5,13 +5,15 @@ import { ScriptArg } from "./ScriptArg";
|
||||
import { NSEnums } from "src/ScriptEditor/NetscriptDefinitions";
|
||||
import { NSFull } from "src/NetscriptFunctions";
|
||||
|
||||
type ExternalFunction = (...args: unknown[]) => unknown;
|
||||
type ExternalFunction = (...args: any[]) => void;
|
||||
|
||||
export type ExternalAPILayer = {
|
||||
[key: string]: ExternalAPILayer | ExternalFunction | ScriptArg[];
|
||||
};
|
||||
|
||||
type InternalFunction<F extends (...args: unknown[]) => unknown> = (ctx: NetscriptContext) => F;
|
||||
type InternalFunction<F extends ExternalFunction> = (
|
||||
ctx: NetscriptContext,
|
||||
) => ((...args: unknown[]) => ReturnType<F>) & F;
|
||||
|
||||
export type InternalAPI<API> = {
|
||||
[Property in keyof API]: API[Property] extends ExternalFunction
|
||||
|
||||
Reference in New Issue
Block a user