typescript - Query regarding using async await in typescript class
问题描述
I am trying to use async await in class in typescript in Netbeans IDE but getting error:
error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.
Please help me resolve the issue. I am not aware how to create Promise constructor if that is the only solution.
Would be great if you if you can point to any complete example for await async usage in class. Also is there any better way for method code synchronization in class that await async. I read some issues here in github but was not able to understand the solution since did not find them complete.
My class method is:
public async login() {
await driver.get("https://fuscdrmsmc293-fa-ext.us.oracle.com/fscmUI/faces/FuseWelcome");
await this.username.sendKeys("cvrqst01");
await this.password.sendKeys("Welcome1");
await console.log("Password entered");
await console.log("username entered");
await console.log("Report");
await searchBox.sendKeys('webdriver');
}
Below is my tscconfig.json file:
{
"version":"1.5",
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"lib": [ "es5", "es2015", "es2015.promise", "dom"],
// types option has been previously configured
"types": [
// add node as an option
"node",
"mocha"
],
// typeRoots option has been previously configured
"typeRoots": [
// add path to @types
"/home/admin/node-v10.15.0-linux-x64/lib/node_modules/npm/node_modules/@types/"
]
}
解决方案
推荐阅读
- c# - 在按钮单击功能上使用 GetMethod 和 Invoke
- javascript - 有没有办法为 foreach 的每次迭代设置状态
- angular - combineLatest 抛出 TypeError
- html - react-html5-camera-photo 上的闪光灯
- angular - 无法将服务正确注入 HttpInterceptor
- ios - 完成在单元格内编辑 textview 后向 tableview 添加另一个单元格
- python - 在 Django 中创建和保存对象时需要管理器吗?
- powerbi - 避免在 Teradata SQL 中手动创建列
- r - R中的CCF函数如何为相同的向量返回不同的相关性,即。corr(x,y) 和 corr(y,x)
- go - CGO中带有C结构的golang结构