0

Consider 2 interfaces,

interface Item {
  id: string
  name: string
  budget: number
}

interface Aggregate {
  budget: number
  estimation: number
}

How to define an interface which is an intersection of Item and Aggregate? By intersection I mean the result type should specify properties which exist both in the first and in the second type? In the example above the result should be

interface ItemAndAggregate {
  budget: number
}

There's Item & Aggregate in TypeScript which is called intersection, but in my opinion the naming is not very correct, because from boolean algebra perspective it's conjunction, A ∪ B. What I'm looking for is the real intersection, disjunction, A ∩ B.

Kasheftin
  • 7,509
  • 11
  • 41
  • 68
  • The type you're looking for is essentially [a union](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types) and not an intersection, although in order to see this you probably have to perform an identity mapped type (as shown [here](https://tsplay.dev/mbKL3W)). Since you're using the word "intersection" to mean what TS calls a union (and presumably vice versa), you might want to look at the linked questions and answers for why they are named that way (it's about values and not properties). – jcalz Jan 20 '23 at 20:57

0 Answers0