struct.intersection
Struct that requires a value to satisfy every given struct.
@defjs/core · Function
Signature
function intersection< const T extends readonly [ StructLike<unknown, unknown, boolean>, ...StructLike<unknown, unknown, boolean>[], ], >( ...structs: T ): T extends readonly [unknown] ? T[0] : T extends readonly [unknown, unknown, ...unknown[]] ? IntersectionStruct<T> : T[0] | IntersectionStruct<T>;
struct.intersection is variadic: pass each struct as its own argument.
-
Parses the input with every struct and merges the results.
-
When every struct is an object struct, the output is one object with the fields of all of them. Keys that none of them declares are removed.
-
When two structs produce incompatible values for the same key, it fails with
invalid_intersection. -
Accepts
nullonly when every struct accepts it, including a nested intersection marked.null(). -
A single struct is returned unchanged, so it keeps its own identity and type, including
.optional()and.null(). Calling it with no structs throwsTypeError, and so does a non-struct argument. -
A nonempty variadic tuple must account for that singleton. Spreading a tuple that may contain only one member infers both the singleton and multi-member results. Its object fields may therefore be optional. A tuple known to contain at least two members keeps the required intersection semantics.
IntersectionStruct<T> is not exported. It is a Struct whose input and output are the intersections of the member types.
Parameters
Prop
Type
...structs? T