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
andtarget
options in tsconfig as"ESNext"
. - Accessing it through
global.AbortController
.