0

I want to load game from local storage and I am getting weird warning. It works, but I like my code clean.

var save = JSON.parse(localStorage.getItem('save000'));
var playerLocation = save[1].playerLocation;

.playerlocation is underlined and I see warning unresolved variable playerLocation

This question is not a duplicate because save variable is not declared in the function signature, but is generated based on local storage. I can only declare JSDoc variables that are declared in the function signature.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Zbyszek Kisły
  • 2,110
  • 4
  • 26
  • 48
  • You should probably clean up your tags, I think it's either `phpstorm` or `intellij` but not both (if any). – fvu Jan 03 '19 at 10:51
  • 2
    I guess the second one is underlined ? Does it works if you do : `var playerLocation = save[1]['playerLocation'];` that should resolve your issue ? – Sylvain Attoumani Jan 03 '19 at 10:52
  • Not sure if the dupe "makes code clean", but it at least changes it from "orange" to "a lot of unnecessary annotations" :) – Jonas Wilms Jan 03 '19 at 10:54
  • 1
    @fvu - PHPstorm is just Intellij with php plugins. – Zbyszek Kisły Jan 03 '19 at 10:59
  • 1
    @Sylvain Attoumani - it works, thank you :) – Zbyszek Kisły Jan 03 '19 at 10:59
  • @JonasWilms the duplicate doesn't solve my problem - it gives me other warnings as var 'save' would have to be declared in the function signature. I could split it into multiple functions, but Sylvain Attoumani already gave me working answer that is a lot less intrusive. – Zbyszek Kisły Jan 03 '19 at 11:08
  • Have a look at the third answer or so, that also explains how to annotate variables inside functions – Jonas Wilms Jan 03 '19 at 11:11
  • @JonasWilms ok, you're right, that one works, thank you. Still like the other way though. – Zbyszek Kisły Jan 03 '19 at 11:14
  • Well the "other way" would be to adopt a less readable identical syntax just to make the IDE happy, most other linters will highlight it the other way round. – Jonas Wilms Jan 03 '19 at 11:19

0 Answers0