Could not find a declaration file for module 'react-faq-component'

Viewed 898

I am trying to use react-faq-component but having an issue. I've more or less copied the same example as that in the link (with additional typscripting).

So far, my code looks like:

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}
        />
    )
}

However, when I run npm start, I get the following error:

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';

I've even run npm i --save-dev @types/react-faq-component as it suggests, but the error I get thereafter is:

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

1 Answers

So, as the suggestion says , we have 2 options to solve it.

  1. Install the types file. (Not working in this case).

  2. Create a .d.ts file and declare the module inside it.

Inside src folder create a new file like, exports.d.ts and inside it write

declare module 'react-faq-component';

There is a third option too. Inside the tsconfig file make "noImplicitAny" to false.

Related