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']
(butjslint
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.
Use JSDoc:
JSDoc the object. Then its members.
@property
for local variables (non parameters){{ member:type }}
syntax Andreas suggested may conflict with Django templates.To document arrays of objects, use
[]
brackets as JSDoc suggests:using a dummy js file with anonymous function expression returning the json literal, as written at http://devnet.jetbrains.com/message/5366907, may be a solution. I can also suggest creating a fake variable that will hold this json value, and use this var as a value of @param annotation to let WebStorm know what the actual type is. Like:
See also http://devnet.jetbrains.com/message/5504337#5504337
All other answers are incorrect for the general case. What if you don't get
data
as a parameter? You don't have JSDoc then:WebStorm will warn that "result.entries" is an unresolved variable (field).
The general solution is to add an
@namespace
declaration: