Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AbortController missing in TypeScript

I am trying to use AbortController in TypeScript.

Given this small file:

const controller = new AbortController();

I get the following error from TypeScript compiler:

src/testAbort.ts:1:24 - error TS2304: Cannot find name 'AbortController'.

1 const controller = new AbortController();
                         ~~~~~~~~~~~~~~~

TypeScript has documentation about AbortController. I also found an issue from Github which has been resolved by merging a pull request that contains the type definitions for AbortController. So it should be available.

My tsconfig.json contains:

{
  "compilerOptions": {
    "target": "ES2018",
    "lib": ["ES2018"],
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "baseUrl": "src"
  },
  "exclude": ["node_modules"],
  "include": ["src/**/*", "__tests__/**/*", "index.ts"],
  "typeRoots": ["./node_modules"]
}

What I have tried:

  • Upgraded to latest TypeScript 3.7.5
  • Setting both lib and target options in tsconfig as "ESNext".
  • Accessing it through global.AbortController.
like image 931
Rene Saarsoo Avatar asked Apr 01 '26 20:04

Rene Saarsoo


1 Answers

It's because you are missing the value DOM in the lib array of your tsconfig.json. If you check the official repo, you will find the AbortController here!

like image 190
nicolasrigaudiere Avatar answered Apr 03 '26 09:04

nicolasrigaudiere



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!