我很难用TypeScript而不是JavaScript编写我的Cypress测试框架。我已经跟踪了很多在线教程,但一直未能使它正常工作。
在下面的Login.ts文件中,我试图创建一个变量,但是我得到了这个错误Cannot find name 'private'.ts(2304):

这些都在我的package.json中:
"dependencies": {
"cypress": "^9.5.2",
"tsify": "^5.0.4",
"typescript": "^4.6.3"
},
"devDependencies": {
"cypress-cucumber-preprocessor": "^4.3.1"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
}发布于 2022-03-28 20:12:27
您没有以正确的方式使用私有。这只能用于类中的成员声明。
你需要用
let accountBalance: number = 0若要使用私有成员var,请执行以下操作
class user {
private _accountBalance : number;
constructor( ) {
}
// Would only include this if you want to be able to set it from externally
set accountBalance( value : number ) {
this._accountBalance = value;
}
// Would only include this if you wanted to get the balance externally
get accountBalance() : number {
return this._accountBalance;
}
}https://stackoverflow.com/questions/71653167
复制相似问题