Intersection types in TypeScript can be described using the & (ampersand) operator.
For example
function makeWeek(): Date & { end: Date } {
//⬅ return type
const start = new Date()
const end = new Date(start.valueOf() + ONE_WEEK)
return { ...start, end } // kind of Object.assign
}
const thisWeek = makeWeek()
thisWeek.toISOString()
thisWeek.end.toISOString()
we can access,
thisWeek.(DateObjFuncs) and this.Week.end.(DateObjFuncs)
Which means we can access the UNION of the types, confused about the (& operator) being called Intersection Type
i am trying to relate this to set theory, intersection means the common..
https://www.typescriptlang.org/play?#code/MYewdgzgLgBA8gOQKIH0DqSkGkYF4YCMADCTAFQwBsR5VNFATACy0DsMA9B4QO4wCWYGAFsIAKC7cAtDOABXKDKliAZnLDAo-cCICGAawCmaQ4f0AKAJQAuGABFdUQzABkMAN4xDYACa2HTjAAvh5iMJwcgKDUMABOhlByMUJQAJ4ADoZiYTCgkLDQujGw+GCGfAGGVtm50F6+eDCl5Y6VBUUAdABuugA2coZwKlYwANTwyOiYWJZZ4XEJSR4w7SttUAA0dT7BMGJBWTWwUAAW-BAmZg3CBsamFjNiJ2cX+u1QIACSAMpwX1AxggA5sNHqdznd2t4fG9Pj8-gCwMDLEA
leaving a typescript playground link of the same code being talked of
||this code is from a course I am doing||