react-canvas-draw icon indicating copy to clipboard operation
react-canvas-draw copied to clipboard

Support for React 18 & typescript

Open leeprobert opened this issue 3 years ago • 3 comments

Had to --force the package to install under [email protected] and also had issues with Typescript types that was resolved with npm i --save-dev @types/react-canvas-draw --force

leeprobert avatar May 12 '22 11:05 leeprobert

Actually still getting errors with typescript: Could not find a declaration file for module 'react-canvas-draw' - the recommended resolution (above) didn't work after all.

leeprobert avatar May 12 '22 11:05 leeprobert

The solution for typescript is to add a file called type.d.ts and put this line in it: declare module 'react-canvas-draw'; - that will be enough for the compiler to accept the import of the module.

leeprobert avatar May 12 '22 11:05 leeprobert

If you need to start doing anything useful with this component in Typescript you'll have to start declaring all the types. My declaration file is currently:

import CanvasDraw from "react-canvas-draw";

// this is required for Typescript to recognise the CanvasDraw package
declare module 'react-canvas-draw'{
    canvasDraw: CanvasDraw | null;
}

leeprobert avatar May 12 '22 12:05 leeprobert