formsy / formsy-react

A form input builder and validator for React JS
MIT License
763 stars 126 forks source link

Update Validation type #660

Open th3fallen opened 2 years ago

th3fallen commented 2 years ago

Update Validation type for custom added validators that leverage the extra argument

Tests run directly on the source code and all dist changes are computed and committed during Formsy release.

th3fallen commented 2 years ago

This resolves the Ts issue regarding validators that leverage the extra argument like so.

validations={ {
                'isNumeric': true,
                'isGte': min,
                'isLte': max,
              } }
export function isGte(values, value, min) {
  if (!value && value !== 0) {
    return true;
  }
  return value >= min;
}
felixmosh commented 2 years ago

@th3fallen sorry for the delay, can you elaborate when do you get a type error? (a small example will be really appreciated).

rkuykendall commented 2 years ago

@felixmosh I think I get this. The type error example here is { 'isLte': max }, where max isn't a boolean or a string or a function, so it does not match the previous type.