gpt4 book ai didi

reactjs - 找不到模块 'react-faq-component' 的声明文件

转载 作者:行者123 更新时间:2023-12-02 18:41:54 27 4
gpt4 key购买 nike

我正在尝试使用react-faq-component但有一个问题。我或多或少复制了与链接中相同的示例(带有额外的 typescript )。

到目前为止,我的代码如下所示:

index.tsx

import React from "react"
import Faq from "react-faq-component"

interface PropTypes {
data: {
title: string,
rows: [{
title: string,
content: string
}]
},
styles: any,
}

const data = {
title: "FAQ (How it works)",
rows: [
{
title: "Lorem ipsum dolor sit amet,",
content: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed tempor sem. Aenean vel turpis feugiat,
ultricies metus at, consequat velit. Curabitur est nibh, varius in tellus nec, mattis pulvinar metus.
In maximus cursus lorem, nec laoreet velit eleifend vel. Ut aliquet mauris tortor, sed egestas libero interdum vitae.
Fusce sed commodo purus, at tempus turpis.`,
},
{
title: "Nunc maximus, magna at ultricies elementum",
content:
"Nunc maximus, magna at ultricies elementum, risus turpis vulputate quam, vitae convallis ex tortor sed dolor.",
},
{
title: "Curabitur laoreet, mauris vel blandit fringilla",
content: `Curabitur laoreet, mauris vel blandit fringilla, leo elit rhoncus nunc, ac sagittis leo elit vel lorem.
Fusce tempor lacus ut libero posuere viverra. Nunc velit dolor, tincidunt at varius vel, laoreet vel quam.
Sed dolor urna, lobortis in arcu auctor, tincidunt mattis ante. Vivamus venenatis ultricies nibh in volutpat.
Cras eu metus quis leo vestibulum feugiat nec sagittis lacus.Mauris vulputate arcu sed massa euismod dignissim. `,
},
{
title: "What is the package version",
content: "3.2"
},
],
}

const styles = {
// bgColor: 'white',
titleTextColor: "blue",
rowTitleColor: "blue",
// rowContentColor: 'grey',
// arrowColor: "red",
}

const config = {
// animate: true,
// arrowIcon: "V",
// tabFocus: true
}

export default function Faq({ data }: PropTypes) {
return (
<Faq
data={data}
styles={styles}
//config={config}
/>
)
}

但是,当我运行 npm start 时,出现以下错误:

Could not find a declaration file for module 'react-faq-component'.implicitly has an 'any' type. Try npm i --save-dev @types/react-faq-component if it exists or add a new declaration(.d.ts) file containing declare module 'react-faq-component';

我什至按照它的建议运行了npm i --save-dev @types/react-faq-component,但此后我得到的错误是:

ERR! 404 Not Found - GEThttps://registry.npmjs.org/@types%2freact-faq-component - Not found

最佳答案

因此,正如建议所说,我们有 2 个选项来解决它。

  1. 安装类型文件。 (在这种情况下不起作用)。

  2. 创建一个 .d.ts 文件并在其中声明模块。

src文件夹中创建一个新文件,例如exports.d.ts并在其中写入

declare module 'react-faq-component';

还有第三种选择。在 tsconfig 文件内将 "noImplicitAny" 设置为 false

关于reactjs - 找不到模块 'react-faq-component' 的声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67892914/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com