Conversation
strictOptional struct
8982082 to
189f8e3
Compare
Member
Author
|
Already exists in the form of |
Member
Author
|
We may still want this. |
rekmarks
commented
Mar 28, 2025
Member
Author
There was a problem hiding this comment.
I moved some stuff around in here but the only new thing is StrictOptionalize and its use in ObjectType.
hmalik88
reviewed
Mar 28, 2025
bd1cdb4 to
cf1bdf7
Compare
hmalik88
reviewed
Mar 28, 2025
hmalik88
reviewed
Mar 28, 2025
hmalik88
reviewed
Mar 28, 2025
hmalik88
reviewed
Mar 28, 2025
strictOptional structexactOptional struct
19e1f15 to
72b1e00
Compare
hmalik88
reviewed
Mar 29, 2025
hmalik88
reviewed
Mar 29, 2025
Member
|
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
Member
Author
|
@FrederikBolding updated description per our discussion. |
Mrtenz
requested changes
Apr 1, 2025
| Type = unknown, | ||
| Schema = unknown, | ||
| > extends Struct<Type, Schema> { | ||
| // eslint-disable-next-line no-restricted-syntax |
Member
There was a problem hiding this comment.
Can you add a comment to clarify why this is necessary?
Mrtenz
approved these changes
Apr 1, 2025
rekmarks
added a commit
to MetaMask/utils
that referenced
this pull request
Apr 2, 2025
Deprecates the local `exactOptional` implementation in favor of the one from `@metamask/superstruct@3.2.0`. See: MetaMask/superstruct#32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.