我试着从Reactive物化中导入组件
import {Navbar, NavItem} from 'react-materialize';
但是当webpack正在编译我的.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-loader
和webpack一起工作。
反作用物化的index.js
看起来是这样的。但是,对于我自己文件中的模块导入,如何解决这个问题呢?
https://github.com/react-materialize/react-materialize/blob/master/src/index.js
发布于 2017-01-13 01:48:12
对于那些想知道我是怎么克服这一切的人来说。我做了一件黑客式的事。
在我的项目中,我创建了一个名为@types
的文件夹,并将它添加到tsconfig.json中以查找它所需的所有类型。所以看起来有点像-
"typeRoots": [
"../node_modules/@types",
"../@types"
]
在里面,我创建了一个名为alltypes.d.ts
的文件。从中找出未知的类型。所以对我来说,这些都是未知的类型,我把它加在那里。
declare module 'react-materialize';
declare module 'react-router';
declare module 'flux';
所以现在打字稿不再抱怨没有找到的类型了。)(现在获胜的情况:)
发布于 2017-04-20 06:40:32
我也犯了类似的错误,但对我来说是react-router
。通过为它安装类型来解决这个问题。
npm install --save @types/react-router
错误:
(6,30): error TS7016: Could not find a declaration file for module 'react-router'. '\node_modules\react-router\index.js' implicitly has an 'any' type.
如果您想禁用站点范围,您可以编辑tsconfig.json
并将noImplicitAny
设置为false
。
发布于 2019-04-02 07:26:12
我对反应型也有同样的问题。最简单的解决方案是添加到tsconfig.json中:
"noImplicitAny": false
示例:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["es6"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext",
"noImplicitAny": false,
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}
https://stackoverflow.com/questions/41462729
复制相似问题