embiem / react-canvas-draw

React Component for drawing in canvas
https://embiem.github.io/react-canvas-draw/
MIT License
902 stars 315 forks source link

Support for React 18 & typescript #142

Open leeprobert opened 2 years ago

leeprobert commented 2 years ago

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

leeprobert commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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