renakre
renakre

Reputation: 8291

TS2705 Error in Visual Studio: An async function or method in ES5/ES3 requires the 'Promise' constructor

I know this error has been discussed in several posts but I could not avoid this error after following all the solutions.

I am developing a react application in VS 2017.

The following code causes me the error. Below I also shared the tsconfig file, which includes "lib":["es2015"]. Any ideas how to solve this?

const fetchData = async () => {//Promise<void> => 
    var dd = await axios.get('api/FeedbackComment/FetchFeedbackActivityByDate',
        {
            params: {
                //activityDate: d3.timeParse("%Y-%m-%d")(d.dateCreated),
                reviewRoundId: props.reviewRoundId,
                submissionId: props.submissionId,
            }
        })
}

Below is my tsconfig.js

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": false,
    "isolatedModules": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es6",
    "allowJs": true,
    "checkJs": false,
    "jsx": "preserve",
    "lib": [
      "es2015"
      //"es6",
      //"dom"
    ],
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "resolveJsonModule": true,
    "noEmit": true
  },
  "exclude": [
    "node_modules",
    //"wwwroot"
  ],
  "include": [
    "src/**/*",
    "**/*.spec.ts"
    //"src",
    //"./src/myIndex.d.ts"
  ]
}

Upvotes: 3

Views: 478

Answers (1)

birwin
birwin

Reputation: 2684

I eliminated this error by changing my ECMAScript version to 6.0

  1. Right-Click the project.
  2. Go to "properties"
  3. Select "Typescript Build"
  4. Adjust the "ECMAScript version"

Upvotes: 2

Related Questions