'Infer props from a functional component
I want to construct a tabbed table but I want to have the option of changing the type of table in each tab. I want to create a type where I can infer the required props the Table prop I pass in. I know I can do this with a generic but is it possible to do without a generic and infer the type from the Table arg?
Here is my current type:
export type Tab<TableProps = any> = {
Table: FunctionComponent<TableProps>;
name: string;
label: string;
} & TableProps;
The ideal solution:
const tab: Tab = {
Table: ListTable,
name: 'foo',
label: 'bar'
columns: [], // <- required props of ListTable inferred from Table
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
