Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 785 Bytes

02_2_intersection-types.md

File metadata and controls

53 lines (38 loc) · 785 Bytes

Intersection Types

Or how to combine types.



Interfaces only support objects, so if you need to combine other types than objects, you will need types

Type example with objects

type Person = {
  name: string;
}

type Engineer = {
  employer: string;
}

type User = Person & Engineer;

const user: User = {
  name: 'Peter',
  employer: 'Apple'
}

Interface example with objects

interface Person {
  name: string;
}

interface Engineer {
  employer: string;
}

interface User extends Person, Engineer {}

const user: User = {
  name: 'Peter',
  employer: 'Apple'
}