You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new struct `exactOptional` that enables strictly optional
properties on `object` structs.
When used with `object()` structs, `{ foo: optional(x()) }` results in
`{ foo?: x | undefined }`. This makes `optional()` incompatible with
e.g. the `Json` type of `@metamask/utils`. Using `exactOptional(x())`,
we instead get exactly optional properties i.e. `{ foo?: x }`.
The name `strictOptional` was previously considered, however
`exactOptional` is in line with the `exactOptionalPropertyTypes`
TypeScript configuration option, whose effect we are trying to achieve.
This implementation is superior to the one currently in
`@metamask/utils` in two ways:
1. The `exactOptional` struct and types should be forward-compatible
with all versions of `@metamask/superstruct`.
2. By modifying the `object` struct in `@metamask/superstruct`, we avoid
creating a second struct that supports `exactOptional`.
0 commit comments