使用Dropzone和Typescript

时间:2017-07-05 21:04:33

标签: typescript dropzone.js

我有一个使用dropzone 4.3的应用程序,并且是用Typescript编写的。在将其转换为打字稿之前,我们必须在Dropzone上设置一个全局变量,一切都很开心。

Dropzone.autoDiscover = false;

我已拉入这些节点包:

    "@types/dropzone": "^4.3.35",
    "dropzone": "4.3.0",

现在,自动发现行给了我这个错误:

Error   TS2686  'Dropzone' refers to a UMD global, but the current file is a module. Consider adding an import instead.

为了解决这个问题,我补充说:

import * as Dropzone from 'dropzone';

现在,我离开了这个错误:

Error   TS2540  Cannot assign to 'autoDiscover' because it is a constant or a read-only property.   

我哪里出错?

1 个答案:

答案 0 :(得分:1)

您可以如下将autoDiscover设置为false

import * as Dropzone from "dropzone";    
const dz = Dropzone
dz.autoDiscover = false;

我通过此链接https://github.com/zefoy/ngx-dropzone-wrapper/blob/fb39139147f3a6d72bcaff51c3c32e2a54e31c9d/src/lib/dropzone.directive.ts#L60

找到了