gpt4 book ai didi

angular - 错误 TS2339 : Property 'entries' does not exist on type 'FormData'

转载 作者:搜寻专家 更新时间:2023-10-30 21:27:41 29 4
gpt4 key购买 nike

我在 Stackoverflow 和网络上进行了搜索,我找到了这个帖子 https://github.com/Microsoft/TypeScript/issues/14813但它不能解决我的问题。我在使用 ng serve --watch 编译我的代码时遇到了这个错误。

Error TS2339: Property 'entries' does not exist on type 'FormData'.

这部分 fd.entries() 触发了错误...知道这里发生了什么吗?

onFileSelected(event) {
const fd = new FormData;

for (const file of event.target.files) {
fd.append('thumbnail', file, file.name);

const entries = fd.entries();
// some other methods are called here e. g. upload the images

for (const pair of entries) {
fd.delete(pair[0]);
}
}
}

我看到那里 ( https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.iterable.d.ts ) 是 entries 的一些接口(interface),但不知何故这对我不起作用。

编辑

我的 tsconfig.json 看起来像这样

{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}

最佳答案

您需要在 tsconfig.json 中的 lib 列表中添加“dom.iterable”,例如:

{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es6",
"lib": [
"es2019",
"dom",
"dom.iterable" // <- there you are
],
// ...
}

关于angular - 错误 TS2339 : Property 'entries' does not exist on type 'FormData' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50677868/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com