gcanti / tcomb-validation

Validation library based on type combinators
MIT License
400 stars 23 forks source link

Maybe value converted from undefined to null after validation? #44

Closed riston closed 7 years ago

riston commented 7 years ago

Not sure if the value should change after the validation is done, it should stay undefined?


const t = require("tcomb-validation");

const Point = t.struct({
    x: t.maybe(t.Number),
    y: t.maybe(t.Number),
}, "Point");

const p1 = Point({ x: 12 });
console.log(p1); 
// Struct { x: 12, y: undefined } -- notice y is undefined

console.log(t.validate({ x: 3234 }, Point)); 
// Struct { errors: [], value: Struct { x: 3234, y: null } } -- notice y here has null value

In code it's strictly set to null? https://github.com/gcanti/tcomb-validation/blob/master/index.js#L132

gcanti commented 7 years ago

it should stay undefined?

Yes, I think it should

gcanti commented 7 years ago

Thanks for reporting, fixed in https://github.com/gcanti/tcomb-validation/releases/tag/v3.2.2