属性 'env' 在类型 'CypressNpmApi' 上不存在

Property 'env' does not exist on type 'CypressNpmApi'

我在尝试使用 cypress.env.json 文件时收到此打字稿错误。

cypress.env.json

{
  "email": "myemail@somewhere.com",
  "password": "Password123"
}

steps.ts

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

import Cypress from 'cypress';

Given(/I login to TMDB/, url => {
  Cypress.env('email'); // <- error here
});

Property 'env' does not exist on type 'CypressNpmApi'

https://github.com/inspiraller/next-cypress-cucumber-boilerplate

感谢 - https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/issues/565#event-4746536875

只需删除我对 Cypress 的导入即可解决。因为这应该可以通过 tsconfig.json

中的打字稿自动获得

更新代码

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

// import Cypress from 'cypress'; <- remove this line

Given(/I login to TMDB/, url => {
  Cypress.env('email'); // <- Now correctly works
});