superstruct
superstruct copied to clipboard
optional() result on returning null after object creation
Given this struct:
const User = object({
userId: string(),
description: optional(string()),
});
creating an object without a description
const user = create({ userId }, User);
results in an object with a description of null
{
userId: "sadfsdfxcbvxd",
description: null,
}
I would expect undefined
here for the description
.
null
adds actually a value and changes the structure of the object by adding a key.
Is this intentional? This feels like a bug to me.
@aldipower For me your use case returns undefined
, see example.
However, I would not expect the property to be set undefined
when the input object doesn't own the property at all.