Intersection Usage Parameters ...types Return value Version History See also

Intersection

import { Intersection } from "@fed1/jsos";

A JSFunction that creates intersection types.

An intersection type matches values that match all of the types that are part of the intersection.

In practice, intersection types are mostly useful for combining traits. A type can implement more than one trait. So if you expect an input, for example, that is both an Iterable and a Stringifyable, you can express this by using an intersection type in the method's signature:

def(printerate, [Intersection(Iterable, Stringifyable)], stringiter => { ... });

The order of parameters to the intersection does not matter. Intersection normalizes the order and always returns the same reference for the same parameters so that:

Intersection(Iterable, Stringifyable) === Intersection(Stringifyable, Iterable)

Usage

Intersection(...types)

Parameters

# Parameter Required? Type Default
... types yes (2) TType (2 or more)

...types

Two or more TType type objects.

Return value

A TIntersectionType that is parameterized by types.

Version History

Feature Since version
Intersection 1.0

See also