跳到主要内容

前言

当一个第三方库组件没有暴露出自己的 type 类型时,可以使用此方法,提取出组件的类型

PickProps

type PickProps<T> = T extends (props: infer P1) => any
? P1
: T extends React.ComponentClass<infer P2>
? P2
: unknown;

使用

import { PlusOutlined } from '@ant-design/icons';

const App: React.FC<PickProps<typeof PlusOutlined>> = (props) => {
return <PlusOutlined {...props}/>;
};