1

我通常能够很容易地解决这个错误,但这次似乎没有任何效果。

我的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

4

1 回答 1

3

创建一个名为shims-element-ui.d.ts以下内​​容的声明文件:

declare module 'element-ui/*';

于 2020-03-10T15:01:13.157 回答