React 的 Cypress-cucumber-typescript 中无法包含 tsconfig.json

Wei*_*Wei 5 cucumber typescript reactjs cypress

我有一个带有 React、Cypress-cucumber-preprocessor、Typescript(在 es5 中输出)的项目。当我使用官方示例其他示例
运行 cypress 时,它存在以下问题:

TypeScript error: cypress/integration/Google/google.ts(5,3): Error TS2304: Cannot find name 'cy'.

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
Run Code Online (Sandbox Code Playgroud)

如果我tsconfig.json在 React 父文件夹中删除,它会修复Syntax Error但仍然有TypeScript error.
所以看起来好像tsconfig.json会出现这个问题,但是项目不应该没有tsconfig.json

这是我的tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}
Run Code Online (Sandbox Code Playgroud)

小智 11

对于错误 TS2304:找不到名称“cy”。

你应该在你的文件顶部添加:

/// <reference types="cypress" />