我拥有一个用JS编写的基于React的组件库,为此,我正在编写一个类型声明文件来帮助进行智能感知和类型检查(对于TS使用者)。组件之一是react-table上的包装器。
import React from 'react';
import ReactTable from 'react-table';
import PropTypes from 'prop-types';
import './reactTable.styles';
import { TableWrapper } from './styles';
import PaginationComponent from './Pagination';
class Table extends React.Component {
getTableInstance = () => this.tableInstance;
render() {
return (
<TableWrapper>
<ReactTable
{...this.props}
className={`${this.props.className} CustomTable`}
ref={table => {
this.tableInstance = table;
}}
/>
</TableWrapper>
);
}
}
Table.defaultProps = {
className: '',
showPaginationBottom: true,
defaultPageSize: 5,
PaginationComponent,
pageSizeOptions: [5, 10, 20, 25, 50],
};
Table.propTypes = {
className: PropTypes.string,
showPaginationBottom: PropTypes.bool,
defaultPageSize: PropTypes.number,
PaginationComponent: PropTypes.node,
pageSizeOptions: PropTypes.arrayOf(PropTypes.number),
};
export default Table;
拥有以下内容是否公平?
//index.d.ts
import ReactTable from 'react-table';
.
.
.
declare var Table: typeof ReactTable;
.
.
.
使用'typeof'为我的'Table'声明类型。