TypeScript错误,“找不到模块的声明文件”-无法修复

时间:2018-08-11 17:16:47

标签: javascript typescript

我通常能够很容易地解决此错误,但是这次似乎没有任何作用。

我的main.ts文件具有以下内容:

import locale from 'element-ui/lib/locale/lang/en';

错误:

ERROR in /Volumes/SuperData/Sites/reelcrafter/rc-ts/src/main.ts
6:20 Could not find a declaration file for module 'element-ui/lib/locale/lang/en'. '/Volumes/SuperData/Sites/reelcrafter/rc-ts/node_modules/element-ui/lib/locale/lang/en.js' implicitly has an 'any' type.
  Try `npm install @types/element-ui` if it exists or add a new declaration (.d.ts) file containing `declare module 'element-ui';`
    4 | import store from './store';
    5 | import ElementUI from 'element-ui';
  > 6 | import locale from 'element-ui/lib/locale/lang/en';
      |                    ^
    7 | import VueDragDrop from 'vue-drag-drop';
    8 | import './styles/element-setup.scss';
    9 | import './bootstrap/amplify-setup';
No lint errors found
Version: typescript 3.0.1, tslint 5.11.0

在根级别的declarations.d.ts中,添加了以下内容:

declare module 'element-ui';

这不能解决。 declare module 'element-ui/*';也没有。我该如何解决?

复制回购:https://github.com/ffxsam/repro-element-ts-bug

1 个答案:

答案 0 :(得分:2)

创建一个名为run:的声明文件,其内容如下:

shims-element-ui.d.ts