I have been reading book effective typescript and there is this paragraph there with code which is not clear to me :
1.
interface Person {
name: string;
}
interface Lifespan {
birth: Date;
death?: Date;
}
type PersonSpan = Person & Lifespan; // why not never type ?
The & operator computes the intersection of two types. What sorts of values belong to
the PersonSpan type?
On first glance the Person and Lifespan interfaces have no properties in common, so you might expect it to be the empty set (i.e., the never type). But type operations apply to the sets of values (the domain of the type), not to the properties in the interface. And remember that values with additional properties still belong to a type. So a value that has the properties of both Person and Lifespan will belong to the intersection type:
const ps: PersonSpan = {
name: 'Alan Turing',
birth: new Date('1912/06/23'),
death: new Date('1954/06/07'),
}; // OK
what if declare
type newPersonSpan = Person | Lifespan; // what are the possible values we can assign now ?
could someone please explain this in more layman language
