Primitive type coercion
const User = attributes({
name: String,
age: Number,
isAdmin: Boolean,
})(class User {});
const userOne = new User({
name: 'Foo Bar',
age: 50,
isAdmin: true,
});
userOne.name; // 'Foo Bar' => no coercion was done
userOne.age; // 50 => no coercion was done
userOne.isAdmin; // true => no coercion was done
const userTwo = new User({
name: null,
age: '100',
isAdmin: undefined,
});
userTwo.name; // '' => coerced `null` to empty string
userTwo.age; // 100 => coerced string to number
userTwo.isAdmin; // undefined => it'll never coerce `undefined`Last updated