Visit complete TypeScript roadmap

← Back to Topics List

Combining Types

In TypeScript, you can combine types using type union and type intersection.

Type Union:

The union operator | is used to combine two or more types into a single type that represents all the possible types. For example:

type stringOrNumber = string | number;
let value: stringOrNumber = 'hello';

value = 42;

Type Intersection:

The intersection operator & is used to intersect two or more types into a single type that represents the properties of all the types. For example:

interface A {
  a: string;

interface B {
  b: number;

type AB = A & B;
let value: AB = { a: 'hello', b: 42 };

Learn more from the following links:

Community is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Roadmaps Best Practices Guides Videos Store YouTube by Kamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© · FAQs · Terms · Privacy


The leading DevOps resource for Kubernetes, cloud-native computing, and the latest in at-scale development, deployment, and management.