"Unresolved variable ..." for global object property name

Getting an inspection warning when trying to access a global from a inner function, if that makes sense. Here is the code:

Note that the `ref` in `global.ref` is getting a warning. Code runs fine though.

I'm probably going to be moving away from using global objects to using dotenv or similar but I'm curious why this is happening.

0
1 comment

The IDE can't know what the global parameter type is; you can use JSDoc annotations to let it know what type is expected:

/**
*
* @type {{ref: number}}
*/
const MY_GLOBAL = {
ref:42
}

/**
*
* @param {MY_GLOBAL} global
*/
function soSomething(global) {
console.log(global.ref);
}
1

Please sign in to leave a comment.