I encountered an issue while attempting to utilize AbortController
in TypeScript.
Here is the code snippet I used:
const controller = new AbortController();
The TypeScript compiler reported the following error:
src/testAbort.ts:1:24 - error TS2304: Cannot find name 'AbortController'.
1 const controller = new AbortController();
~~~~~~~~~~~~~~~
Although TypeScript provides documentation about AbortController, there was also an issue on Github that has since been resolved with a pull request containing the necessary type definitions for AbortController.
In my tsconfig.json
file, I have specified:
{
"compilerOptions": {
"target": "ES2018",
"lib": ["ES2018"],
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"baseUrl": "src"
},
"exclude": ["node_modules"],
"include": ["src/**/*", "__tests__/**/*", "index.ts"],
"typeRoots": ["./node_modules"]
}
Approaches I have taken to resolve this:
- Upgraded TypeScript to version 3.7.5
- Set both
lib
andtarget
options in tsconfig to"ESNext"
. - Tried accessing it through
global.AbortController
.