grantila / suretype

Typesafe JSON (Schema) validator
508 stars 9 forks source link

Is it possible to parse numeric strings so the resulting type is number? #10

Closed escobar5 closed 3 years ago

escobar5 commented 3 years ago

I'm using suretype for Express input validation, what I want is for example, to validate req.params and req.query, all variables in those objects come as strings, but I want the type resulting from calling EnsureFunction<> to have the inputs that are valid numbers to be number type, is this possible? any ideas on how to accomplish that? thanks

escobar5 commented 3 years ago

I found out how to do it:

compile(schema, {
  ajvOptions: { 
      coerceTypes: true
  }
});