New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[react-signature-canvas] Add definitions #41396
[react-signature-canvas] Add definitions #41396
Conversation
@ksocha Thank you for submitting this PR! Because this is a new definition, a DefinitelyTyped maintainer will be reviewing this PR in the next few days once the Travis CI build passes. In the meantime, if the build fails or a merge conflict occurs, I'll let you know. Have a nice day! |
馃憢 Hi there! I鈥檝e run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let鈥檚 review the numbers, shall we? These typings are for a package that doesn鈥檛 yet exist on master, so I don鈥檛 have anything to compare against yet! In the future, I鈥檒l be able to compare PRs to react-signature-canvas with its source on master. Comparison details 馃搳
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there, I'm the creator/maintainer of the react-signature-canvas
package.
Thanks for submitting these types and tests @ksocha !! 馃檪
The main issue I see here is that this relies on types from signature_pad
v3, whereas react-signature-canvas
uses v2 under-the-hood. v3 has been in beta for a while and has had some bugs (it seems to be unmaintained).
As this is a separate package that should only be used at build-time, it might be able to duplicate the dependency on signature_pad
without increasing bundle size or causing dependency mismatch errors, but I'm not sure. Idk how the TS compiler would even handle that. There's no package.json
here either, I'm not sure how that works for DefinitelyTyped (haven't read up on the contributing guidelines yet).
But even if it could be duplicated without issues, there could be type inconsistencies if v3 changes them without a major release (could pin the version here to prevent that though)
The other thing is that I'm working on rewriting the package in TS already. I've been contributing heavily to tsdx
the past month, fixing bugs and adding features so I could use it in the rest of the packages I maintain, including react-signature-canvas
, so that put a bit of a hold on the rewrite (v0.12 was released recently).
Have been looking to push an alpha soon, but something popped up and I'm out of the country for most of January. If this passes review prior to then, I'm totally ok with this being released as a stop-gap solution (gives me more time to polish a release too!!), but just noting that this may cause some churn for users.
Also not sure what the process is for adding deprecation notices to DT packages is (i.e. when TS is supported internally, these should be deprecated).
import * as React from 'react'; | ||
import SignaturePad from 'signature_pad'; | ||
|
||
export interface SignatureCanvasProps extends SignaturePad.SignaturePadOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better as ISignatureCanvasProps
, but maybe even better to be named as IReactSignatureCanvasProps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against this as other type definitions rarely use this convention of prepending I
to the interface name. I personally think it brings no value and I've even seen linter rules to prevent naming interfaces like this.
I will change the name to ReactSignatureCanvasProps
though.
import SignaturePad from 'signature_pad'; | ||
|
||
export interface SignatureCanvasProps extends SignaturePad.SignaturePadOptions { | ||
canvasProps?: React.CanvasHTMLAttributes<HTMLCanvasElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is HTMLCanvasElement
the right generic type? I thought it should be canvasProps<T>?: React.CanvasHTMLAttributes<T>
, but I'm not 100% sure. If you could provide an explanation, would be helpful to understand better 馃檹 .
See same discussion in agilgur5/react-signature-canvas#25 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the only proper way to type the attributes of a canvas element. This is how it's used in React
itself:
canvas: React.DetailedHTMLProps<React.CanvasHTMLAttributes<HTMLCanvasElement>, HTMLCanvasElement>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, confusing why it would be a generic then 馃 I guess it passes type-checking in the tests, so that does mean it works o.o.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's generic because of consistency. In the React's type definitions, CanvasHTMLAttributes
is defined as:
interface CanvasHTMLAttributes<T> extends HTMLAttributes<T> {
height?: number | string;
width?: number | string;
}
IntrinsicElements
interface which defines all html elements looks like:
[...]
button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
canvas: React.DetailedHTMLProps<React.CanvasHTMLAttributes<HTMLCanvasElement>, HTMLCanvasElement>;
caption: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
[...]
Generic type passed to HTMLAttributes
is used mostly (if not only) in event handlers definitions, e.g.: onFocus?: FocusEventHandler<T>;
Hi @agilgur5 !
Type definitions for
As this is quite a big change, have you considered bumping a major version number of the lib? This way, people who would use v1 could still use definitions from DT, while all who would use v2 will get definition file generated by the lib itself. |
Ah, so this is using types from
Yes, I have considered that:
Suffice to say, there's quite a lot of details to consider when making breaking/major changes, and most of those seem like very big cons to me. But even without getting into those details & trade-offs, the release of third-party typings on DT during an internal TS rewrite shouldn't significantly impact the release of the internal rewrite. They are third-party, and, on top of that, that would suggest that timing, instead of content, is the biggest factor in deciding to do a major. |
velocityFilterWeight={2} | ||
onBegin={(event: MouseEvent) => {}} | ||
onEnd={(event: MouseEvent) => {}} | ||
canvasProps={{ title: 'canvas' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some frequently used canvasProps
are width
, height
, and style
or className
(CSS backgroundColor
is a topic that pops up occasionally) -- would probably be good to use those instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I plan to have at least one alpha release to make sure the transpiled output hasn't changed in breaking ways (similar to the v1 alpha), but otherwise was planning on releasing it as v1.1.0.
It will work fine as well. For people still using v1.0.x (or those who do not want to update to v1.1.x or newer), DT type definitions will be a way to go.
If someone updates to >= v1.1.x, all he has to do is to remove @types/react-signature-canvas
from the dependencies.
Chiming in as a DT maintainer: DT has a npm task that deprecates an Also: when resolving |
After 5 days, no one has reviewed the PR 馃槥. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience! |
@armanio123 From my point of view all work is done. |
It's my first added definition file. Please, be gentle 馃檹
https://github.com/agilgur5/react-signature-canvas
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present)..d.ts
files generated via--declaration
dts-gen --dt
, not by basing it on an existing project.tslint.json
should be present and it shouldn't have any additional or disabling of rules. Just content as{ "extends": "dtslint/dt.json" }
. If for reason the some rule need to be disabled, disable it for that line using// tslint:disable-next-line [ruleName]
and not for whole package so that the need for disabling can be reviewed.tsconfig.json
should havenoImplicitAny
,noImplicitThis
,strictNullChecks
, andstrictFunctionTypes
set totrue
.