简体   繁体   中英

Typescript doesn't know what FormData is

When trying to use window.FormData I get the following error:

The name 'FormData' does not exist in the current scope

The same happens to FileReader

You can check a feature exists using:

if (window.FormData) {
    alert('Yes');
}

This relies on falsey checks - if you want to be explicit, use.

if (typeof FormData !== 'undefined') {
    alert('Yes');
}

add dom to the lib array in the tsconfig.json of your project.

{
  "compilerOptions": {
    ...
    "lib": ["es2018", "dom"], // add `dom` to the array
    ...
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM