Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

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]);
        }
    }
}

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.

EDIT

My tsconfig.json looks like this

{
    "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"
        ]
    }
}
like image 572
b00r00x0 Avatar asked Jun 04 '18 09:06

b00r00x0


Video Answer


2 Answers

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
    ],
    // ...
}
like image 177
gkri Avatar answered Sep 18 '22 14:09

gkri


TypeScript isn't supporting it unless you are compiling to ES6.

"target": "es5"

If it is es6, then it will work.

like image 28
Padmapriya Vishnuvardhan Avatar answered Sep 16 '22 14:09

Padmapriya Vishnuvardhan