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?

5
  • 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 :) Commented Jun 7, 2015 at 9: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. Commented Jun 7, 2015 at 9: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? Commented Jun 7, 2015 at 9: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(?). Commented Jun 7, 2015 at 9: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. Commented Jun 7, 2015 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.