sajad torkamani

Suppose you have this component:

import React from 'react';

interface Props {
  name: string;
  age?: number;
}

const SomeComponent: React.FC<Props> = ({ name, age }) => (
  <div>{name} - {age}</div>
)

You can extract the type of <SomeComponent> like so:

type PropsOfSomeComponent = React.ComponentProps<typeof SomeComponent>

const test: PropsOfSomeComponent = { name: 'Alice' } // ✅ age is optional

This can be useful if you have some third-party component from an NPM package but that package doesn’t export the component’s types.

TypeScript playground link