【发布时间】:2019-12-03 23:02:21
【问题描述】:
我正在将现有的自定义命令转换为 typescript,但遇到了问题。我的自定义命令返回一个Promise,赛普拉斯会自动处理并转换为Cypress.Chainable,但打字稿不知道这个魔法,所以它会抛出一个错误。这可能吗?有什么建议吗?
function test(): Cypress.Chainable<string> {
return new Cypress.Promise<string>(resolve => {
resolve("some data");
});
}
Cypress.Commands.add("test", test);
给我:
[ts] Type 'Bluebird<string>' is missing the following properties from type 'Chainable<string>': and, as, blur, check, and 75 more.
我已经通过cy.wrap()将返回值转换为Cypress.Chainable,使用其他命令处理了这个问题,但我不知道如何使用Promise正确执行此操作:
function test(): Cypress.Chainable<string> {
return new Cypress.Promise<string>(resolve => {
resolve("some data");
}).then(data => {
return cy.wrap(data);
});
}
给我:
[ts] Type 'Bluebird<Chainable<string>>' is missing the following properties from type 'Chainable<string>': and, as, blur, check, and 75 more.
或者如果我切换它:
function test(): Cypress.Chainable<string> {
return cy.wrap(
new Cypress.Promise<string>(resolve => {
resolve("some data");
})
);
}
给我:
[ts]
Type 'Chainable<Bluebird<string>>' is not assignable to type 'Chainable<string>'. Type 'Bluebird<string>' is not assignable to type 'string'.
【问题讨论】:
标签: typescript cypress