-
-
Notifications
You must be signed in to change notification settings - Fork 120
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do I need to install @types/react-signature-canvas
?
#106
Comments
For v1.0.x, yes.
The latest published package is older than most of the TS changes (since #42). I had been meaning to publish a v1.1.0-alpha with the built-in TS types, but never quite got to it (I maintain a lot of projects 🙃, this is one of the most stable of them all). Once that is published and you install v1.1.x+, you will no longer need |
For anyone looking to lazy load this component and struggling with the exact type you need for When you lazy load a component like this... const SignatureCanvas = lazy(() => import('react-signature-canvas')); the type you get for What we really need is the We need to extract it out. This is where the following two type utils come into picture. type UnwrapLazyComponent<T> = T extends React.LazyExoticComponent<
infer ComponentType
>
? ComponentType
: never; This first one extracts the // eslint-disable-next-line @typescript-eslint/no-explicit-any
type InstanceTypeOf<T extends new (...args: any) => any> = T extends new (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any
) => infer K
? K
: never; This second one extracts the You can then get your required type like this and pass it on to type ReactSignatureCanvasType = InstanceTypeOf<
UnwrapLazyComponent<typeof ReactSigCanvas>
>;
const canvasRef = useRef<ReactSignatureCanvasType>(null); Courtesy : Myself and Copilot with a little bit of toying around. |
@types/react-signature-canvas
?
|
Now that it's written in typescript and can export the typings from the tsx files directly, do I still need to install the
@types
package?I have checked the published package for
react-signature-canvas
and that doesn't contain any typings all by itself.Here's my tsx code where the ref complains of type issues.
Here, the ref on the component complains.
I have looked at other issues like #61 but those examples don't work.
The text was updated successfully, but these errors were encountered: