tsconfig.json 文件与访问 Json 对象中的键之间有什么联系?

问题描述 投票:0回答:0

我的代码有效,测试通过。但问题是 body 键在 Visual Studio Code 上带有红色下划线。正如我所说,即使只有 body 键带下划线(settingsReq.states[0].elements[0].body.TR),代码也能正常工作。但有趣的是,当我在 tsconfig.json 文件中将 baseurl 行获取到命令行时,红色下划线消失了。我不明白的问题是什么? baseUrl 和访问 Json 对象中的键有什么关系?顺便问一下,你觉得我的 tsconfig.json 文件怎么样。我想使用最新版本的 tsconfig,但我对此知之甚少。

tsconfig.json 文件;

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noFallthroughCasesInSwitch": true
  },
  "include": ["playwright", "tests"]
}

测试文件;

import {settingsReq } from 'fixtures/request-body/settings';

let text=settingsReq.states[0].elements[0].body.TR
await expect(fsPage.thankText).toContain(text)

request-body文件夹中的settings.ts文件;

export const settingsReq = {
  "states": [
    {
      "initial": false,
      "style": "fs",
      "elements": [
        {
          "type": "label",
          "visible": true,
          "body": {
            "TR": "Test"
          },
          "key": "P",
          "detail": null,
        }
      ],
      "key": "P"
    }
  ],
  "ts": []
}
javascript node.js typescript tsconfig playwright-test
© www.soinside.com 2019 - 2024. All rights reserved.