LoginSignup
0
1

More than 3 years have passed since last update.

React/TypeScript: 他のコンポーネントの型注釈(型の定義)を取得する方法備忘録

Posted at

ComponentPropsを使用する。

コード

const HogeTypes = ComponentProps<typeof Hoge>

応用: chakra-uiの提供するHeadingコンポーネントの型注釈を取得し継承?しつつ独自のtextを定義している。

import { ComponentProps } from "react"
import { Heading } from "@chakra-ui/react";

type Props = ComponentProps<typeof Heading> & {
  text: string;
};
0
1
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
0
1