Course contentsShow
← React
Lesson 2329 of 2,39651. TypeScript with React BasicsFree lesson

Basic Function Component Type Annotation

Learn the fundamental syntax for typing React function components and their props interface.

Basic Function Component Type Annotation

What you'll learn: How to add TypeScript type annotations to React function components and their props.


After mastering performance optimization patterns, it's time to add TypeScript's type safety to your React components. Type annotations catch bugs before runtime and provide excellent IDE autocomplete.

The Core Pattern

A React function component is just a function that returns JSX. In TypeScript, you annotate it like any function—specify what props it receives and what it returns:

interface ButtonProps {
  label: string;
  onClick: () => void;
}

function Button({ label, onClick }: ButtonProps): JSX.Element {
  return <button onClick={onClick}>{label}</button>;
}

The pattern breaks down to three parts:

  1. Props interface — Define the shape of your props object
  2. Parameter annotation — Tell TypeScript the destructured props match that interface
  3. Return type — Explicitly mark the function as returning JSX (optional but clear)

Simpler Return Type

Most developers use React.FC (Function Component) or omit the return type entirely since TypeScript infers it:

// Using React.FC
const Button: React.FC<ButtonProps> = ({ label, onClick }) => {
  return <button onClick={onClick}>{label}</button>;
};

// Or let TypeScript infer the return type
function Button({ label, onClick }: ButtonProps) {
  return <button onClick={onClick}>{label}</button>;
}

Both approaches work. The second is more common in modern React because React.FC had quirks with children in older TypeScript versions.

Key Takeaway: Type your function components by creating a props interface, then annotating the component's parameter with that interface—TypeScript handles the rest, giving you type safety and autocomplete throughout your component.