react-to-pdf
react-to-pdf copied to clipboard
Using react-to-pdf with typescript
This package doesn't have a types file to use with typ[escript
Any news on this?
Has anyone managed to solve this problem?
I solve this issue. Firstly, Create a folder typings then create file index.d.ts inside the folder. then declare module declare module 'react-to-pdf'
. Then add "typeRoots": [ "./typings", "./node_modules/@types" ]
inside tsconfig.json.
Folder Structure:
- typings
- index.d.ts `declare module 'react-to-pdf'
rror-ts7016-could-not-find-a-declaration-file-for-module-xyz-has-an-any-type-ecab588800a8)
[Reference](https://pjausovec.medium.com/how-to-fix-e
I solve this issue. Firstly, Create a folder typings then create file index.d.ts inside the folder. then declare module
declare module 'react-to-pdf'
. Then add"typeRoots": [ "./typings", "./node_modules/@types" ]
inside tsconfig.json.Folder Structure:
typings
- index.d.ts `declare module 'react-to-pdf'
rror-ts7016-could-not-find-a-declaration-file-for-module-xyz-has-an-any-type-ecab588800a8)
[Reference](https://pjausovec.medium.com/how-to-fix-e
This doesn't work for me
It works now but there's still error in the code as {toPdf} still has an implicit type of any with red underline
Try declaring a module like this in a file that ends with .d.ts
:
declare module 'react-to-pdf' {
import { RefObject } from 'react';
function ReactToPdf(
targetRef?: RefObject,
filename?: string,
x?: number,
y?: number,
options?: object,
onComplete?: function,
scale: number
): ReactNode<{ toPdf: () => void; targetRef: MutableRefObject }>;
export = ReactToPdf;
}
You still have to explicitly add a typing to toPdf like this: {({ toPdf }: never) => ()}
v1 has been just released and it's built with TS, please see README for more details/examples.