Typescript 在量角器中使用本机承诺

Typescript 在量角器中使用本机承诺,typescript,protractor,Typescript,Protractor,有没有办法使用量角器filter接受返回量角器自身承诺类型的函数,以及我自己返回本机承诺的函数 const myFilter = async(e: ElementFinder): Promise<boolean> => { ... } myElements.filter(myFilter) constmyfilter=async(e:ElementFinder):Promise=>{ ... } myElements.filter(myFilter) 这会引发TypeScr

有没有办法使用量角器
filter
接受返回量角器自身承诺类型的函数,以及我自己返回本机承诺的函数

const myFilter = async(e: ElementFinder): Promise<boolean> => {
...
}
myElements.filter(myFilter)
constmyfilter=async(e:ElementFinder):Promise=>{
...
}
myElements.filter(myFilter)
这会引发TypeScript编译错误

TS2345:类型为“(e:ElementFinder)=>>Promise”的参数不能分配给类型为“(元素:>ElementFinder,索引?:数字)=>布尔值| Promise”的参数。 类型“Promise”不可分配给类型“boolean | Promise”。 类型“Promise”不可分配给类型“Promise.Promise”。 类型“承诺”中缺少属性“取消”


顺便说一句,我自己不能创建量角器的承诺,因为deprecaion()

好的,如果这仍然是相关的,我再次开始使用测试,这次我马上找到了解决方案

这些助手打开了
量角器.promise.promise
和本机
promise
之间的桥梁

const-toNativePromise=(p:pregrator.promise.promise):promise=>{
返回新承诺((res,rej)=>{
p、 然后(res)。捕捉(rej)
})
}
const-toProtractorPromise=(原生承诺:promise):dragor.promise.promise=>{
const deferred=量角器.promise.deferred();
const progratorpromise=延期承诺;
原生承诺。然后(延期。履行)。捕获(延期。拒绝)
回程量角器
}
无论如何,为了解决最初的问题,你可以这样写:

const myFilter = async(e: ElementFinder): Promise<boolean> => { ... }
const myFilterForProtractor = (e) => toProtractorPromise(myFilter(e))

constmyfilter=async(e:ElementFinder):Promise=>{…}
常数myfilterFormotractor=(e)=>toProtractorPromise(myFilter(e))