-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add exactOptional struct
#32
New issue
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
Conversation
strictOptional struct
8982082 to
189f8e3
Compare
|
Already exists in the form of |
|
We may still want this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved some stuff around in here but the only new thing is StrictOptionalize and its use in ObjectType.
bd1cdb4 to
cf1bdf7
Compare
strictOptional structexactOptional struct
19e1f15 to
72b1e00
Compare
|
Why do we wanna do this at the fork level instead of just using what already exists in |
Adds a new struct `strictOptional` that enables strictly optional properties on `object` structs.
a505589 to
368778e
Compare
|
@FrederikBolding updated description per our discussion. |
| Type = unknown, | ||
| Schema = unknown, | ||
| > extends Struct<Type, Schema> { | ||
| // eslint-disable-next-line no-restricted-syntax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment to clarify why this is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecates the local `exactOptional` implementation in favor of the one from `@metamask/superstruct@3.2.0`. See: MetaMask/superstruct#32
Adds a new struct
exactOptionalthat enables strictly optional properties onobjectstructs.When used with
object()structs,{ foo: optional(x()) }results in{ foo?: x | undefined }. This makesoptional()incompatible with e.g. theJsontype of@metamask/utils. UsingexactOptional(x()), we instead get exactly optional properties i.e.{ foo?: x }.The name
strictOptionalwas previously considered, howeverexactOptionalis in line with theexactOptionalPropertyTypesTypeScript configuration option, whose effect we are trying to achieve.This implementation is superior to the one currently in
@metamask/utilsin two ways:exactOptionalstruct and types should be forward-compatible with all versions of@metamask/superstruct.objectstruct in@metamask/superstruct, we avoid creating a second struct that supportsexactOptional.