antd的Table组件在d.ts中的写法如下
export interface TableProps<T> {
dataSource?: T[];
columns: TableColumnConfig<T>[];
}
export default class Table<T> extends React.Component<TableProps<T>, any> {
...}
如果用以下方法写Table组件
<Table rowSelection={rowSelection}
columns={columns}
dataSource={listState.data}/>
如果listState.data为any时不会报错,但如果有Interface时则会提示
Error:(124, 20) TS2322:Type 'DataInterface[]' is not assignable to type 'T[]'.
Type 'DataInterface' is not assignable to type 'T'.
搜索网上其他问题,参考https://github.com/Microsoft/...,将代码改为
type CusTable = new () =>Table<DataInterface>;
const CusTable = Table as CusTable
<CusTable rowSelection={rowSelection}
columns={columns}
dataSource={listState.data}/>
在
const CusTable = Table as CusTable
中报错
TS2352:Type 'typeof Table' cannot be converted to type 'CusTable'.
求解到底应该怎么写.
参考:
https://github.com/ant-design...
https://github.com/ant-design...