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:
JavaScript
x
16
16
1
declare module 'read-more-react' {
2
3
import React from 'react';
4
5
declare const ReadMoreReact: React.FunctionComponent<ReadMoreReactProps>;
6
7
}
8
9
interface ReadMoreReactProps {
10
text: string
11
min: number
12
ideal: number
13
max: number
14
readMoreText: string
15
}
16
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:
JavaScript
1
6
1
{
2
"include": [
3
"path/to/your/index.d.ts",
4
]
5
}
6
Also use this code instead:
JavaScript
1
16
16
1
declare module 'read-more-react' {
2
import React from 'react';
3
4
interface ReadMoreReactProps {
5
text: string
6
min: number
7
ideal: number
8
max: number
9
readMoreText: string
10
}
11
12
const ReadMoreReact: React.FC<ReadMoreReactProps>;
13
14
export default ReadMoreReact;
15
}
16