TS2318

TS2318: Cannot find global type 'AsyncIterableIterator'.

Broken Code ❌

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": ["es2018", "dom"],
    "strict": true,
    "esModuleInterop": true,
    "moduleResolution": "node"
  }
}

Solution:

This issue is often related to the TypeScript configuration not including the necessary libraries that define modern JavaScript features like AsyncIterableIterator. To ensure that TypeScript supports Symbol.asyncIterator properly, your TypeScript configuration needs to either target esnext or explicitly include the esnext.asynciterable library if you're using a targeted subset of features from ECMAScript proposals.

Fixed Code ✔️

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": ["es2018", "dom", "esnext.asynciterable"],
    "strict": true,
    "esModuleInterop": true,
    "moduleResolution": "node"
  }
}