So I know the question is probably super confusing but basically I have a file in my node project that when importing one of the exports it will set the value of variable in the global scope as a getter. Basically this means that you can call the same value over and over again and get different results. For example:
magicIncrement.js:
let count = -1;
module.exports = {
get magicIncrement() {
Object.defineProperty(global, 'increment', {
get: () => {
count += 1;
return count;
},
});
},
};
index.js:
let { magicIncrement } = require('./magicIncrement');
console.log( 'increment:', increment );
const test = increment;
console.log('"test"s value doesn\'t change.')
console.log('test:', test);
console.log('test:', test);
setTimeout(() => {
console.log('...but "increment"s value always will')
console.log( 'increment:', increment );
}, 1010);
The result is that increment will increase every time the variable is called.
The issue is that the variable isn't recognized by the IDE since 'increment' technically doesn't exist as far as VSCode is aware. Is there any way to fix this issue?
P.S. I tried simply setting the export (in this example "magic increment") as the name of the global variable/getter (in this case "increment") but it seems like setting a variable in a file (like via destructing as done in index.js) simply cuts the link between global.[var name] and [var name].