https://github.com/woowa-typescript/woowahan-typescript-with-react-example-code/tree/main/8장
interface Component <P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {}
class Component<P, S> {
/* ... 생략 */
}
class PureComponent<P = {}, S = {}, SS = any> extends Component <P, S, SS> {}
interface WelcomProps {
name : string
}
class Welcome extends React.Component<WelcomeProps> {
/* ... 생략 */
}
// 함수 선언을 사용한 방식
function Welcome(props: WelcomeProps) : JSX.Element {}
// 함수 표현식을 사용한 방식 - React.FC 사용
const Welcome: React.FC<WelcomeProps> = ({name}) => {};
// 함수 표현식을 사용한 방식 - JSX.Element를 반환 타입으로 지정
const Welcome = ({name}: WelcomeProps): JSX.Element => {};
type PropsWithChildren<P> = P & { children?: ReactNode | undefined };
// example 1
type WelcomeProps = {
children: "천생연분" | "더 귀한 분" | "귀한 분" | "고마운 분";
};
// example 2
type WelcomeProps = { children: string };
// example 3
type WelcomeProps = { children: ReactElement };
interface ReactElement<
P = any,
T extends string | JSXElementConstructor<any> =
| string
| JSXElementConstructor<any>
> {
type: T;
props: P;
key: Key | null;
}