A struct which allows the property of an object to be absent, or to be present as long as it's valid and not set to undefined.
undefined
This struct should be used in conjunction with the object from this library, to get proper type inference.
Use exactOptional and object from @metamask/superstruct@>=3.2.0 instead.
exactOptional
object
@metamask/superstruct@>=3.2.0
A struct to check if the given value is valid, or not present.
const struct = object({ foo: exactOptional(string()), bar: exactOptional(number()), baz: optional(boolean()), qux: unknown(),});type Type = Infer<typeof struct>;// Type is equivalent to:// {// foo?: string;// bar?: number;// baz?: boolean | undefined;// qux: unknown;// }
The struct to check the value against, if present.
A struct which allows the property of an object to be absent, or to be present as long as it's valid and not set to
undefined
.This struct should be used in conjunction with the object from this library, to get proper type inference.
Deprecated
Use
exactOptional
andobject
from@metamask/superstruct@>=3.2.0
instead.Returns
A struct to check if the given value is valid, or not present.
Example