错误TS2339:类型"FormData"上不存在属性“条目" [英] Error TS2339: Property 'entries' does not exist on type 'FormData'
问题描述
我在Stackoverflow和网络上进行搜索,发现此线程 https://github. com/Microsoft/TypeScript/issues/14813 ,但不能解决我的问题.使用ng serve --watch
编译代码时遇到此错误.
I searched on Stackoverflow and on the web, I found this thread https://github.com/Microsoft/TypeScript/issues/14813 but it does not solve my problem. I run into this error while compiling my code with ng serve --watch
.
错误TS2339:类型"FormData"上不存在属性条目".
Error TS2339: Property 'entries' does not exist on type 'FormData'.
带有fd.entries()
的这部分会触发错误...知道这里发生了什么吗?
This part with fd.entries()
triggers the error... any idea what is going on here?
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
的某些界面,但对我来说不起作用.
I saw that there (https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.iterable.d.ts) is some interface for entries
but somehow this does not work for me.
编辑
我的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"
]
}
}
推荐答案
您需要将"dom.iterable"添加到tsconfig.json
中的lib
列表中,例如:
You need to add "dom.iterable" to your lib
list in tsconfig.json
, for example:
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es6",
"lib": [
"es2019",
"dom",
"dom.iterable" // <- there you are
],
// ...
}
这篇关于错误TS2339:类型"FormData"上不存在属性“条目"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!