How to fight tons of unresolved variables warning in WebStorm?

前端 未结 6 1820
陌清茗
陌清茗 2020-12-04 09:19

I have a function that takes data from server:

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

WebStorm says that someVar

6条回答
  •  悲&欢浪女
    2020-12-04 10:14

    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:

    function niceApiCall(parameters) {
      const result = await ...  // HTTP call to the API here
      for (const e of result.entries) {
        .. // decorate each entry in the result
      }
      return result;
    }
    

    WebStorm will warn that "result.entries" is an unresolved variable (field).

    The general solution is to add an @namespace declaration:

    function niceApiCall(parameters) {
      /** @namespace result.entries **/
      const result = await ...  // HTTP call to the API here
      for (const e of result.entries) {
        .. // decorate each entry in the result
      }
      return result;
    }
    

提交回复
热议问题