我正在尝试从react-materialize中导入组件-
import {Navbar, NavItem} from 'react-materialize';
但是当webpack正在编译我的文件时,.tsx它会为上述内容引发错误-
.tsx
ERROR in ./src/common/navbar.tsx (3,31): error TS7016: Could not find a declaration file for module 'react-materi alize'. 'D:\Private\Works\Typescript\QuickReact\node_modules\react-materialize\l ib\index.js' implicitly has an 'any' type.
这个的任何解决方案。我不确定如何解析该导入语句以与ts-loaderwebpack一起使用。
ts-loader
该index.js反应-Materialise的长相很喜欢这一点。但是如何解决此问题的模块导入到我自己的文件中..
index.js
https://github.com/react-materialize/react- materialize/blob/master/src/index.js
对于那些想知道我如何克服这个问题的人。我做了些骇人听闻的事情。
在我的项目中,我创建了一个名为的文件夹@Types,并将其添加到tsconfig.json中,以从中查找所有必需的类型。所以看起来有点像这样-
@Types
"typeRoots": [ "../node_modules/@types", "../@types" ]
在其中,我创建了一个名为的文件alltypes.d.ts。从中查找未知类型。所以对我来说,这些是未知类型,我在那添加了它。
alltypes.d.ts
declare module 'react-materialize'; declare module 'react-router'; declare module 'flux';
所以现在打字稿不再抱怨找不到的类型了。:)现在赢赢局面:)