Skip to content
Advertisement

create index.d.ts for read-more-react npm package

I have a typescript project,

I am trying to import read-more-react but beacuse it doesn’t have a @type defined for it, I need to write the index.d.ts file myself (place it under @type/read-more-react),

I have tried this:

declare module 'read-more-react' {

    import React from 'react';

    declare const ReadMoreReact:  React.FunctionComponent<ReadMoreReactProps>;

}

interface ReadMoreReactProps {
    text: string
    min: number
    ideal: number
    max: number
    readMoreText: string
}

but it doesn’t seems to work,

can anyone help me in how to successfully implement the index.d.ts file, what am I missing ?

Advertisement

Answer

Inside your tsconfig.json file, you need to include your index.d.ts file. You can do so by adding the following:

{
  "include": [
    "path/to/your/index.d.ts",
  ]
} 

Also use this code instead:

declare module 'read-more-react' {
    import React from 'react';

    interface ReadMoreReactProps {
        text: string
        min: number
        ideal: number
        max: number
        readMoreText: string
    }

    const ReadMoreReact: React.FC<ReadMoreReactProps>;

    export default ReadMoreReact;
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement