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

ffx*_*sam 1 javascript typescript element-ui

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

我的main.ts文件有这个:

import locale from 'element-ui/lib/locale/lang/en';
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

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

declare module 'element-ui';
Run Code Online (Sandbox Code Playgroud)

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

复制仓库: https: //github.com/ffxsam/repro-element-ts-bug

小智 5

创建一个名为的声明文件,shims-element-ui.d.ts其中包含以下内容:

declare module 'element-ui/*';
Run Code Online (Sandbox Code Playgroud)