Uh oh!
There was an error while loading. Please reload this page.
feat: Add exactOptional struct - #32
Conversation
strictOptional struct8982082 to
189f8e3Comparerekmarks
commented
Mar 28, 2025
Already exists in the form of |
rekmarks
commented
Mar 28, 2025
We may still want this. |
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.
Uh oh!
There was an error while loading. Please reload this page.
bd1cdb4 to
cf1bdf7CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
strictOptional structexactOptional struct19e1f15 to
72b1e00CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
FrederikBolding
commented
Mar 31, 2025
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
368778eComparerekmarks
commented
Mar 31, 2025
@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.
Can you add a comment to clarify why this is necessary?
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.