Answer the question
In order to leave comments, you need to log in
How to fix component type error?
encountered an error
TS2345: Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'T'. 'string | string[] | undefined' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | string[] | undefined'. Type 'undefined' is not assignable to type 'T'. 'undefined' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | string[] | undefined'.
interface IFilters<U extends string | string[] | undefined> {
setData(filterType: FiltersType, prevValue: U, value: U): void;
buttonsGroup: JSX.Element;
source: "partners" | "accounts";
config: {
type: FiltersType;
isMulti: boolean;
label: string;
placeholder: string;
labelClass: string;
}[];
}
const Filters = <T extends string | string[] | undefined>({
setData,
config,
buttonsGroup,
source,
}: IFilters<T>): JSX.Element => {
return (
<div className={styles.partnersFilters}>
{config.map((filter) => (
<Filter<string | string[] | undefined>
type={filter.type}
source={source}
isMulti={filter.isMulti}
setData={(prevValue, value) => setData(filter.type, prevValue, value)}
label={filter.label}
placeholder={filter.placeholder}
labelClass={filter.labelClass}
key={filter.type}
/>
))}
{buttonsGroup}
</div>
);
};
<Filters<string[]> config={filtersConf} source="partners" setData={setData} buttonsGroup={<ButtonsGroup />} />
Answer the question
In order to leave comments, you need to log in
And what type is the setData prop for Filter? What value comes into it?
setData={(prevValue, value) => setData(filter.type, prevValue, value)}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question