我正在尝试将一个简单的 React 组件加载到我的应用程序中(特别是React-rating)。
我运行 Visual Studio,并确保将其添加到我的packages.json
,并安装所有依赖项(请参阅帖子底部的图像)。
现在,我尝试遵循使用该组件的标准说明。在我的 TSX 文件的顶部,我写道:
var Rating = require('react-rating');
当我使用组件时,我只是使用<Rating />
现在,这给出了:
TS2604: JSX element type 'Rating' does not have any construct or call signatures.
如果我改为像这样加载模块:
import * as Rating from 'react-rating';
然后我得到:
Could not find a declaration file for module 'react-rating'. '/Likvido.CreditRisk/node_modules/react-rating/lib/react-rating.js' implicitly has an 'any' type.
Try `npm install @types/react-rating` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-rating';`
我猜是因为我使用了 Typescript,但在这种情况下,我该如何导入组件呢?
我的依赖: