Sergey Panfilov Sergey Panfilov - 6 months ago 317
Javascript Question

How to fight a lots of unresolved variables warning in Webstorm

Ok, I have a function which takes a data from ajax:

function getData(data){
console.log(data.some_unres_var);
}


Webstorm says that
some_unres_var
- is unresolved variable.
I don't know what to do with lots of such warnings.

I see few options:


  • suppress warnings;

  • add a json source file with fields (more details);

  • use arrays-like syntax:
    data['some_unres_var']
    (but
    jslint
    warn me to didn't do this);

  • ???



Also Webstorm offering me to create namespace for the "data" (add an annotation like
/** @namespace data.some_unres_var*/
), create such field, or rename it.

Answer

Use JSDoc:

/**
 * @param {{some_unres_var:string}} data
 */
function getData(data){
    console.log(data.some_unres_var);
}