Basically, when I dynamically import a file, I want it to match some specifications. I want my file to have some way of showing that, so that intellisense understands what my file needs to be shaped like (essentially a schema for a typescript module).
//My module
import * as fetch from 'node-fetch';
import { Cache } from '../cache'; //Because this path is relative, the path of this script must be immediately under the root of the project
let jq = "";
let error = "";
let url = "https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.js";
export function desc(){
return "Adds jquery to the hackscripts list.";
}
export function name(){ return "jqhack" }
export function id(){ return "sys.modsExtra.jqhack" }
export async function preload(cache: Cache){
let err = false;
jq = await cache.load_cached("jqhack.jq", ()=>fetch(url).then(res => res.text(), err => {
err = true;
return `[ERROR] ${err}`;
}));
if(err) {
error = `Failed to fetch "${url}".)`;
return false;
}
return true;
}
export function getErr(){
return error;
}
export function impl(sys){
sys.hackscripts.register("Jquery 3.2.1", jq);
}
interface Module{
name():string;
id():string;
preload(cache: Cache):Promise<void>;
impl(sys:SystemStatus, cache: Cache):ModuleStatus;
getErr?():string;
}
My goal isn't that the module loader on my side of the code understands what type it is, my goal is that the modules themselves know what they need to export.