1

I've been working on a simple Typescript file to get an understanding of Typescript which uses asynchronous functions to make API calls. For my program, these functions are executed when a certain button is clicked, and would use the fetch() function to grab a JSON object and display certain data from it on an HTML page. I have these functions as type Promise since they use async/await and don't return anything, yet when trying to compile with tsc it gives me the error

error TS2705: An async function or method in ES5 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.

I have gone into my tsconfig.json file to add ES2015 into lib, yet it still gives me this same error when trying to compile. Is there something I am doing wrong? I've also tried using both ES6 for lib and target but the same error happens.

2
  • "Is there something I am doing wrong?" Yes, I would assume it. But it's almost impossible to help without more details. Commented Sep 16, 2024 at 19:37
  • Welcome to Stack Overflow. Please edit to provide a minimal reproducible example we can use to see what you're seeing. Otherwise we just have to guess what you're seeing, which is pretty difficult to do remotely. How are you running tsc? Are you trying to call it on a single file and therefore tsconfig.json is ignored as per this q? Commented Sep 16, 2024 at 20:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.