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

129
Visualizações
How to define Type of dynamically added global variables for Intellisense

I am defining four global variables from a forEach loop using a line similar to this:

global[name] = buffer

with buffer being the type from node.js

and currently have the very ugly way to get my intellisense for it by having this after the loop:

// next line only so intellisense works, ALWAYS comment out before running
const btMapProvinces = Buffer.alloc(1), btMapTerrain = Buffer.alloc(1), btMapRivers = Buffer.alloc(1), btMapHeightmap = Buffer.alloc(1);

Now as i learned about how to use JSDoc to get Intellisense for arguments in modules i was sure i could use that to get Intellisense for my variables instead, but after reading through the whole documentation i can't seem to get it working.

My current attempt looks like this:

/**
 * @var {Buffer} btMapProvinces
 * @var {Buffer} btMapTerrain
 * @var {Buffer} btMapRivers
 * @var {Buffer} btMapHeightmap
 */

but it just doesn't work at all, no matter if it is right before the global[name] = buffer line, at the beginning of the script, or after the forEach...

I previously also tried using @name like this:

/**
 * @name btMapProvinces
 * @type {Buffer}
 * @name btMapTerrain
 * @type {Buffer}
 * @name btMapRivers
 * @type {Buffer}
 * @name btMapHeightmap
 * @type {Buffer}
 */

though this did not work aswell

The last two hours i spent looking through other asks, of which these are the ones i found the most interesting:

  • It's a pretty similar situation to this i think, except that i'm not using Typescript: JSDoc: How to specify the type of an implicit global variable for a JS code snippet?
  • This is why i tried @var: Specify type of globals declared in another file
  • I feel like this could potentially answer my question, but i don't understand the answer: How to document the type of a global variable with JSDOC
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Whats the reason your type needs to be dynamic? Your curent attempt

/**
 * @var {Buffer} btMapProvinces
 * @var {Buffer} btMapTerrain
 * @var {Buffer} btMapRivers
 * @var {Buffer} btMapHeightmap
 */

suggests that you know very well which Objects you want to have on the global object. So you could just extend the global Type like in this answer

about 4 years ago · Juan Pablo Isaza Relatório
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