首页 > 解决方案 > 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/"
         ]
    }

标签: typescriptclassasync-await

解决方案


推荐阅读