Intersecting with something other than a type

It is possible to intersect with a type, primitive, and an interface. Intersecting with primitive is useless, since a number cannot be a boolean at the same time. However, intersecting an interface is valid as much as intersecting with a type. The same rules apply for a type or an interface, with regard to intersecting:

interface InterfaceA {
m1: string;
}

interface InterfaceB {
m2: string;
}

type TypeAB = InterfaceA & InterfaceB;

While the most common case of intersection touches type and interface, it is possible to intersect classes. Intersection with classes are rare and it creates a type that cannot be instantiated. Only the public fields are extracted from each class to create a field:

type ClassAb = ClassA & ClassB;
const classAb: ClassAb = { m1: "test", m2: "test2" };
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.156.107