如何防止JSON文件中的IDE(WebStorm)中的未解析变量消息?

时间:2019-03-02 13:54:46

标签: javascript json webstorm

给出以下JSON文件:

example.json

{
  "labels": [
    {
      "AB": {
        "title": "example title",
        "desc": "example description"
      }
    },
    {
      "CD": {
        "title": "another example title",
        "desc": "another example description"
      }
    }
  ]
}

它可以在函数中使用:

const jsonData = require('./example.json');
export default function() {
  const labels = jsonData.labels;
  const entries = labels[0]['AB'].title; // Unresolved variable title
}

该代码在应用程序中有效。

但是,似乎IDE无法识别JSON文件中存在该标题键。

是否可以布局JSON文件结构,以便IDE知道需要什么键?

0 个答案:

没有答案