Test November
Test November

Reputation: 13

error TS2550: Property 'any' does not exist on type 'PromiseConstructor'

**

Code : async function fetchDataWithDelay(delay: number, data: string) { return new Promise((resolve, reject) => { setTimeout(() => resolve(data), delay); }); }

async function fetchAnyData() {
  try {
    const result = await Promise.any([
      fetchDataWithDelay(3000, "Data 1"),
      fetchDataWithDelay(1000, "Data 2"),
      fetchDataWithDelay(2000, "Data 3"),
    ]);
    console.log("First resolved data:", result);  // "Data 2"
  } catch (error) {
    console.error("Error:", error);
  }
} fetchAnyData();

**

error TS2550: Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later. I had already given the lib as given below

lib: ["es2021","dom"]

Node version is v22.8.0, tsc version 5.7.2 ide is vs code still getting the same error in terminal with cmd

Can anyone suggest

Upvotes: 1

Views: 115

Answers (1)

Patrick Schlieker
Patrick Schlieker

Reputation: 91

Changing also the target option should fix this:

{
"compilerOptions": {
  ...
  "target": "ES2021",
  ...
  }
}

Upvotes: 0

Related Questions