In TypeScript, both type and interface can be used to define the shape of an object, but there are specific benefits to using type.

Type Aliases

Key Benefits

Example

Using type for a component's props:

type MyComponentProps = {
  title: string;
  isVisible: boolean;
};

const MyComponent: FC<MyComponentProps> = ({ title, isVisible }) => {
  if (!isVisible) return null;

  return (
    <div>
      <h1>{title}</h1>
    </div>
  );
};

export { MyComponent };