mozmorris / react-webcam

Webcam component
https://codepen.io/mozmorris/pen/JLZdoP
MIT License
1.66k stars 281 forks source link

make all props optional #392

Open sean-adams opened 10 months ago

sean-adams commented 10 months ago

All component props are either not required and/or have reasonable defaults in defaultProps, but Typescript will still complain if you don't provide them because they are not marked as optional in WebcamProps.

Achieving this did require optional chaining on onUserMedia and onUserMediaError as well as coercing imageSmoothing to a boolean.

mozmorris commented 10 months ago

@sean-adams thank you for sending this PR.

What does your TypeScript setup look like? Can you supply a reproducible example? We don't see this issue on any of the multiple projects this library is used on. It's a long time since the types were added but I remember that the default props were properly inferred. I believe this was the recommended setup at the time. For example, I think you would agree the optional chaining is not actually needed at runtime, since those props have defaults.

If there is now an issue with this setup, it would be great if we could avoid the code changes that are not actually needed. Perhaps by extending the PropTypes with typeof WebCam.defaultProps?