在类型声明文件中使用typeof

我拥有一个用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'声明类型。

jiang8com 回答:在类型声明文件中使用typeof

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3094882.html

大家都在问