TypeScript 中缺少 AbortController
AbortController missing in TypeScript
我正在尝试在 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. I also found an 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
访问它。
这是因为您 tsconfig.json 的 lib 数组中缺少值 DOM
。
如果你查看官方仓库,你会发现 AbortController here!
我正在尝试在 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. I also found an 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
访问它。
这是因为您 tsconfig.json 的 lib 数组中缺少值 DOM
。
如果你查看官方仓库,你会发现 AbortController here!