“文件”对象不具有“路径”属性。 (TypeScript)

时间:2019-04-17 13:09:36

标签: javascript html5 typescript

我正在将来自浏览器的File对象(通过拖放)传递给这样的函数:

// .... logic here...
accept(file)

public static accept(file: File) {
   console.log(file)
   /* prints:
      => lastModified: 1555453309243
         lastModifiedDate: Wed Apr 17 2019 01:21:49 GMT+0100 (GMT+01:00) {}
         name: "test.txt"
         path: "test.txt" --> as you can see there is a path variable in here.
         size: 16
         type: "text/plain"
         webkitRelativePath: ""
         __proto__: File
   */

   console.log(file.name) // => prints 'test.txt'
   console.log(file.size) // => prints '16'
   console.log(file.path) // => !! error given. path does not exists in File object. Also IDE does not show this parameter in IDE autocomplete list.
}

给出错误:

Property 'path' does not exist on type 'File'.ts(2339)

为什么File没有path参数?如何确保路径存在? File还有其他类型吗?这是HTML5拖放。

如果我这样做:

public static accept(file: any) {
   alert(file.path);
}

它显示了相对路径:

path

0 个答案:

没有答案