为什么 react-select 在使用自定义类型时会显示 TypeScript 警告以分配给选项属性?

问题描述 投票:0回答:0

我收到警告:

Type 'Participant[]' is not assignable to type 'readonly (Participant | GroupType)[]
对于我将
[p1]
分配给
options
的行。

对于以下情况,当使用 react-select 时,每个选项的类型都是

Participant

const p1: Participant = {
    name: "Bill",
    id: "1"
}

export function MyCustomMultiSelect<
    Participant,
    IsMulti extends boolean = true,
    GroupType extends GroupBase<Participant> = GroupBase<Participant>
    >( props: Props<Participant, IsMulti, GroupType>) {
    return (
        <CreatableSelect options={[p1]} {...props}/>
    );
}

我的用例不涉及组,我正在按照 here.

的说明进行操作
reactjs typescript react-select
© www.soinside.com 2019 - 2024. All rights reserved.