Skip to content
Advertisement

Tag: react-proptypes

How to remove Object is possibly ‘null’ TS2531 warning when using PropTypes.InferProps and default parameters?

I have a simple React component that adds two numbers together. It’s written in TypeScript and using @types/prop-types. Typescript complains that first and second could possibly be ‘null’ ts(2531), but they have default parameter values. Making these PropTypes.number.isRequired will obviously make the warning go away, but I don’t want them required. I know I can make this warning go away

Advertisement