原理就是包一层,生成一个新的组件.
@emotion/styled默认自身不带泛型透传的功能...
import { Table, TableProps } from 'antd';
import styled from '@emotion/styled';
interface MyTableProps<RecordType> extends TableProps<RecordType> {}
const StyledTable = styled(Table)<MyTableProps<any>>`
// 样式
`;
export default function MyTable<RecordType>(props: MyTableProps<RecordType>) {
return <StyledTable {...(props as MyTableProps<any>)} />;
}
当然,你也可以选择不透传泛型,直接写死类型.
const RootTable = styled(Table<在此指定你的类型>)`
`;
虽然没有自动类型推断那么爽了..但没办法...总算也是解决了问题.