【发布时间】:2022-08-19 14:49:02
【问题描述】:
我对打字稿相当陌生,我正在使用@tanstack/react-table 并在useReactTable 钩子周围构建了一个TableComponent,它需要2 个道具data 和columns 并将它们传递给useReactTable 钩子。
问题是数据和列道具是可以包含不同类型对象的数组并且它们是连接的,我怎样才能正确输入它们?现在我在TableComponent 中遇到错误
type OrderTableProps = {
data: OrdersRow[];
columns: typeof ordersTableColumns;
onRowClick?: (row: Row<OrdersRow>) => void;
}
type ContainerTableProps = {
data: ContainersRow[];
columns: typeof containersTableColumns;
onRowClick?: (row: Row<ContainersRow>) => void;
}
export type TableComponentProps = PropsWithChildren
& TableComponentBaseProps
& (OrderTableProps | ContainerTableProps);
// TableComponent
const ReactTableComponent = ({data, columns}: TableComponentProps) => {
const table = useReactTable({
data, -> Type \'OrdersRow[] | ContainersRow[]\' is not assignable to type \'OrdersRow[]\'
columns,
getCoreRowModel: getCoreRowModel(),
});
return (
<Table> ... </Table>
}
标签: reactjs typescript react-table