【发布时间】:2020-06-23 11:50:31
【问题描述】:
我一直在尝试将组件 SelectSearchResult 包裹在来自 react-select 的 AsyncSelect 周围。我希望我的自定义组件的道具与AsyncSelect 几乎相同,但有一些例外。
import AsyncSelect, { Props as AsyncSelectProps } from "react-select/async";
// works, but Props allows all properties
type Props = AsyncSelectProps<{ label: string; value: string }>;
const SelectSearchResult = (props: Props) => {
return <AsyncSelect {...props} />;
};
我以为我只需要省略我不想要的键。
type Props = Omit<AsyncSelectProps<{ label: string; value: string }>, "loadOptions">;
但是,当我检查 Props 时,它现在具有以下格式,我不知道它为什么会变成这种形状。
type Props = {
[x: string]: any;
[x: number]: any;
}
【问题讨论】:
标签: reactjs typescript react-select