如何使用 react-select props typings

How to make use of react-select props typings

我正在尝试编写一个包装 AsyncSelect 的组件,但是在这种情况下,它们的 props 类型具有通用性,我不确定如何实现它。

这是我的代码:

export class PipTagSelect extends React.Component<AsyncProps> {
    constructor(props:AsyncProps ) {
        super(props);
    }

    render() {
        return (
            <AsyncSelect
                isMulti
                cacheOptions
                {...this.props}
            />
        );
     }
}

编译器报错AsyncProps<OptionType>需要一个类型参数。这在查看类型定义时很有意义。

然而,我从来没有在包装组件时为 props 提供类型参数。我不确定我应该做什么。

将您的class设置为通用

 export class<T> PipTagSelect extends React.Component<AsyncProps<T>> {
    constructor(props:AsyncProps<T>) {
        super(props);
    }

    render() {
        return (
            <AsyncSelect
                isMulti
                cacheOptions
                {...this.props}
            />
        );
     }
 }

看看这个on github