DEV Community

Discussion on: A different way of handling required arguments in javascript functions

Collapse
 
barendb profile image
Barend Bootha

Nice article, some thoughts form the sidelines.

My approach to this is to use something like Joi or Yup to validate the input. Our teams also follow a convention that if you have more than 3 arguments to make it an object.

The other reason to use something like Joi or Yup is you can have more finite control of what's passed in, so instead of having validation statements to check if a persons page is between 0-120 for example you can define that in a schema.

Thirdly if you use TypeScript this the required check is a non-issue. The compiler will validate that for you.