antd - 关于在Typescript使用Table 组件的问题,基类相关
本文介绍了antd - 关于在Typescript使用Table 组件的问题,基类相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
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...
这篇关于antd - 关于在Typescript使用Table 组件的问题,基类相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文