AbortController missing in TypeScript
Asked Answered
A

1

10

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.
Abutting answered 22/1, 2020 at 12:1 Comment(0)
S
15

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!

Stauffer answered 24/1, 2020 at 8:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.