Javascript ';文件';对象没有';路径';财产。(打字稿)

Javascript ';文件';对象没有';路径';财产。(打字稿),javascript,html,typescript,Javascript,Html,Typescript,我正在将来自浏览器的文件对象(通过拖放)传递给如下函数: // .... 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) {}

我正在将来自浏览器的
文件
对象(通过拖放)传递给如下函数:

// .... 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)
为什么
文件
没有
路径
参数?如何确保路径存在?
文件
还有其他类型吗?这是一个HTML5的下降

如果我这样做:

public static accept(file: any) {
   alert(file.path);
}
它显示了相对路径:


我可以访问它。这是HTML5拖放项目。我已经更新了这个问题。看看这个。我就是不能用静态输入。我如何欺骗IDE和网页包,使其具有
路径
。如果该属性存在,您始终可以通过
(任何文件)访问它。路径
@mbojko是的,这就成功了。谢谢您可以将此作为一个答案来编写。理想情况下,您可以创建自己的接口,如
接口MyFile扩展文件{path:string;/*etc*/}
,并使用它。但是,
文件
有一个
路径
属性的地方有记录吗?您应该知道您是否只支持某些特定或非标准的环境。啊,React Dropzone正在添加此属性。我想这应该是React Dropzone打字脚本的一部分。。。可能是一个
DropZoneFile
DropZoneFolder
,它使用可选的
路径
属性扩展
文件
?因为他们没有在库中完成这项工作,所以我想您需要为自己的代码完成这项工作。