导入DefinitelyTyped模块的角度

时间:2018-03-16 21:25:35

标签: angular typescript definitelytyped

我遇到与此帖子相同的问题=> Finding the correct import for a third party DefinitelyTyped module

我正在尝试将VanillaTilt安装到我的Angular(TS)项目中。使用此index.d.ts ...我将d.ts保存在与app.component.ts相同的目录中,如下所示

    import VanillaTilt from 'vanilla-tilt';
    VanillaTilt.init(document.createElement('a'), { perspective: 1000  });

但我得到以下ts错误 ERROR in src/app/app.component.ts(3,8): error TS1192: Module '"vanilla-tilt"' has no default export.

我也试过d.ts的{​​{3}},但我一直在Cannot read property 'init' of undefined

有没有人对如何在agular5中使用this version有任何建议?

1 个答案:

答案 0 :(得分:0)

现在可以在npm上输入打字。首先安装它们

npm install --save-dev @types/vanilla-tilt

然后删除您当地的.d.ts文件

接下来,导入的正确语法是

import { VanillaTilt } from 'vanilla-tilt';

因为VanillaTilt有一个命名导出,而不是默认导出。

相关问题