错误TS2339:类型"FormData"上不存在属性“条目" [英] Error TS2339: Property 'entries' does not exist on type 'FormData'

查看:565
本文介绍了错误TS2339:类型"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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆