3

...

doChunk().then(function (results) {
   angular.forEach(results, function (info) {
      if (info.data.fields.worklog) {
         configProcess.results.push(info.data);

...

The above is just a sample from my AngularJS application, but it's the same issue for all data (and vanilla JS) that's returned from somewhere else - like an HTTP request in this case.

results - is the result of an HTTP request and contains an array of objects.

So when I loop over this array I access different properties of these objects. All is fine and it works, but how can I declare what the different properties of these methods are?

Basically what I want is to get rid of code inspection errors from WebStorm like these: Unresolved variable fields at line 106.

It makes perfect sense to me why it's reported, but how do I address it?

Benny Bottema
  • 11,111
  • 10
  • 71
  • 96
jBoive
  • 1,219
  • 1
  • 14
  • 40
  • What do you mean by "All is fine and it works, but how can I declare what the different properties of these methods are?"? Expand this and I might be able to help :) – Jim O'Brien Jun 07 '15 at 09:41
  • 1
    You can right-click the the area near scrollbar and chose 'Customize hightlighting level' and in that dialog, click 'Configure Inspections'. There you can turn off the 'Unresolved variable' under JS. – marekful Jun 07 '15 at 09:42
  • IntelliJ / WebStorm complains about: "Unresolved variable fields" in the above code. Which makes sense, since how is anyone/anything supposed to know that the object "info" actually contains: "info.data.fields.worklog"? Do I need to do something like: info.data = info.data ? info.data : {}; info.data.fields = info.data.fields ? info.data.fields : {}; Must be a better way? – jBoive Jun 07 '15 at 09:44
  • @marekful - Yes, I could do that. But I don't wish to disable it globally, just in cases like this. Maybe I would be sufficient if I could disable the inspection on a case by case basis - but that doesn't seem possible(?). – jBoive Jun 07 '15 at 09:50
  • I understand your frustration. it did annoy me a lot and could only come up with these 2 solutions: disable it globally OR define those properties individually but this latter seems unrealistic. – marekful Jun 07 '15 at 09:58

1 Answers1

2

I can suggest using JSDoc to document such objects received by ajax calls. See How to fight tons of unresolved variables warning in Webstorm?, for example

benomatis
  • 5,536
  • 7
  • 36
  • 59
lena
  • 90,154
  • 11
  • 145
  • 150