michaeldzjap / react-signature-pad-wrapper

A React wrapper for signature pad
MIT License
199 stars 27 forks source link

Use in typescript #27

Closed DmitryDadeco closed 2 years ago

DmitryDadeco commented 3 years ago

Problem: Is it possible to use react-signature-pad-wrapper in typescript? Something like this npm i @types/react-signature-pad-wrapper

Temporary solution:

I declared module in my custom types, Create file react-signature-pad-wrapper.d.ts with content declare module 'react-signature-pad-wrapper'

michaeldzjap commented 3 years ago

As far as I know there are no type declarations available for this package, no. But feel free to add them yourself If you'd like. I have thought about completely re-writing this package in typescript actually, but I don't have time for this at the moment.

DmitryDadeco commented 3 years ago

As far as I know there are no type declarations available for this package, no. But feel free to add them yourself If you'd like. I have thought about completely re-writing this package in typescript actually, but I don't have time for this at the moment.

thanks for answer

michaeldzjap commented 2 years ago

The source of this project has been converted to TypeScript as of v2.

ascherkus commented 2 years ago

Hi there! Thanks for updating the library to TypeScript!

I'm testing out v2.0.0 and getting the following error when attempting to import:

Could not find a declaration file for module 'react-signature-pad-wrapper'. 'node_modules/react-signature-pad-wrapper/dist/react-signature-pad-wrapper.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/react-signature-pad-wrapper` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-signature-pad-wrapper';`  TS7016

I notice that there is a index.d.ts and SignaturePad.d.ts file however I believe you need to add "types" to your published package.json: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

I tested this out locally and it appears to work (I'm no pro at publishing TypeScript modules so apologies if I've led you astray!)

michaeldzjap commented 2 years ago

I notice that there is a index.d.ts and SignaturePad.d.ts file however I believe you need to add "types" to your published package.json:

Yes, you are right. I forgot to do that. Will do a patch release to fix that shortly.

michaeldzjap commented 2 years ago

Should be fixed in v2.0.1

ascherkus commented 2 years ago

Just tested out v2.0.1 and confirms it works perfectly. Thanks for the quick fix :fire: