【发布时间】:2020-05-08 14:11:18
【问题描述】:
我正在尝试在 TypeScript 中使用 AbortController。
鉴于这个小文件:
const controller = new AbortController();
我从 TypeScript 编译器收到以下错误:
src/testAbort.ts:1:24 - error TS2304: Cannot find name 'AbortController'.
1 const controller = new AbortController();
~~~~~~~~~~~~~~~
TypeScript 有关于 AbortController 的文档。我还发现了一个issue from Github,它已通过合并包含 AbortController 类型定义的拉取请求来解决。所以它应该是可用的。
我的tsconfig.json 包含:
{
"compilerOptions": {
"target": "ES2018",
"lib": ["ES2018"],
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"baseUrl": "src"
},
"exclude": ["node_modules"],
"include": ["src/**/*", "__tests__/**/*", "index.ts"],
"typeRoots": ["./node_modules"]
}
我尝试过的:
- 升级到最新的 TypeScript 3.7.5
- 将 tsconfig 中的
lib和target选项设置为"ESNext"。 - 通过
global.AbortController访问它。
【问题讨论】:
标签: typescript fetch-api