5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[React + TypeScript] Reactで特定のコンポーネントのPropsの型を取り出す方法

Last updated at Posted at 2019-08-05

下記のようにReact.ComponentPropsを使用する。

interface Props {
  name: string
  age: number
}

const Component: React.FC<Props> = props => <div />

interface CustomizedComponentProps extends React.ComponentProps<typeof Component> {
  location: string
}
/**
 * 下記のようになる
 * interface CustomizedCommponentProps {
 *   name: string;
 *   age: number;
 *   location: string
 * }
 */

参考

Typescript React: Access component property types

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?