Course contentsShow
← TypeScript
Lesson 436 of 1,79610. Intersection TypesFree lesson

Intersection with Functions

Intersecting function types creates an overloaded function signature that must satisfy all function shapes.

Intersection with Functions

You'll learn: How intersecting function types creates an overloaded signature that must satisfy all shapes at once.

What This Means

When you use the & operator with function types, TypeScript doesn't create a function that can be either type. Instead, it creates a callable type that must satisfy all the function signatures simultaneously. This is fundamentally different from how intersections work with objects.

Think of it like agreeing to meet two different sets of requirements at the same time—your function must be callable in every way described by each type.

How Function Intersections Behave

type LogString = (message: string) => void;
type LogNumber = (value: number) => void;

type Logger = LogString & LogNumber;

// This function must satisfy BOTH signatures
const log: Logger = (input: string | number): void => {
  console.log(input);
};

log("hello");  // Valid - satisfies LogString
log(42);       // Valid - satisfies LogNumber

The implementation signature needs parameters broad enough to accept what either signature requires. The function becomes overloaded—callers can use it with a string OR a number, and TypeScript knows both are valid.

The Practical Effect

Function intersections create overloaded functions. You're essentially saying: "This function can be called in multiple distinct ways, and it must handle all of them."

Key Takeaway: Intersecting function types produces an overloaded function that accepts all the combined call signatures, requiring an implementation compatible with every variant.