Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda