We have scripts that are evaluated in a JS VM call on node that declares a few contextual globals, like in the code below. The question is, at development time, when a developer is working on some-script.js, how can we have VSCode provide intellisense to the author of that file when aGlobalThing is referenced?
The project itself has both TS and JS support, but the scripts must be written in JS for unrelated reasons. Is there some sort of comment header that can be put in each script file at the top that will give VSCode enough of a hint that it can understand that the aGlobalThing variable already exists with the IVmGlobals type info? A typedef, a global comment, some combo with an embedded but comment-wrapped import?
// code-runner.ts
export interface IVmGlobals {
aGlobalThing: {
a: number;
b: string;
};
};
export async function runCode(codeSnippet) {
const context = vm.createContext({
aGlobalThing: { a: 123, b: 'xyz', },
} as IVmGlobals);
await vm.runInContext(codeSnippet, context);
}
// some-script.js
// will assign 123, but how can a developer get
// intellisense while writing this file that indicates
// the presence of aGlobalThing as existing, and having
// a member called `a` that holds number?
const a = aGlobalThing.a;
//... more code, etc.