Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Unable to declare global variable type for use in JS files for VM evals

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.
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!