We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]
Using defaulted with optional type and undefined default value creates an object without default field.
defaulted
optional
undefined
Issue comes between version 0.16.0 and version 0.16.2, almost same time another issue was fixed about optional (#1106, @cwouam)
Defaulted optional field exists with default value to undefined.
const UserInfo = type({ name: string(), age: defaulted(optional(number()), undefined) }); const user = create( { name: "3" }, UserInfo ); /* * user = { * name: "3" * age: undefined * } */
Defaulted optional field does not exist.
const UserInfo = type({ name: string(), age: defaulted(optional(number()), undefined) }); const user = create( { name: "3" }, UserInfo ); /* * user = { * name: "3" * // missing age field * } */
https://codesandbox.io/s/superstruct-optional-defaulted-bug-p79txr?file=/src/index.ts:478-579
I think we could modify the behaviour to make defaulted of an optional convert to a required property.
Another way to change this without breaking would be to add another type undefined to allow for undefined type without being optional.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
[BUG]
Description
Using
defaulted
withoptional
type andundefined
default value creates an object without default field.Issue comes between version 0.16.0 and version 0.16.2, almost same time another issue was fixed about
optional
(#1106, @cwouam)Expected Behaviour
Defaulted optional field exists with default value to undefined.
Actual Behaviour
Defaulted optional field does not exist.
Reproduction
https://codesandbox.io/s/superstruct-optional-defaulted-bug-p79txr?file=/src/index.ts:478-579
Opinion
I think we could modify the behaviour to make defaulted of an optional convert to a required property.
Another way to change this without breaking would be to add another type
undefined
to allow forundefined
type without beingoptional
.The text was updated successfully, but these errors were encountered: