RecipesChapter 10: TypeScript and React

Typing Higher-Order Components

Recipe 10.5 from The TypeScript Cookbook

function withTitle<U extends { title: string }>(
  title: string,
  Component: React.ComponentType<U>
) {
  return withInjectedProps({ title }, Component);
}
Open in TypeScript Playground →