formatOptionLabel - Type 'unknown' is not assignable #5155
-
Hello! I'm attempting to change the option labels in the menu/control, but am running into TS errors after upgrading from const formatOptionLabel = (
{ label, name }: Partial<UserOption>, // destructured properties are defined in UserOption
{ context }: string,
): ReactNode => {
if (context === 'value') {
return <>{label}</>;
}
return (
<div>
<p>{name}</p>
</div>
);
};
return (
<Search
/* formatOptionLabel returns the TS error below
Type '(data: Partial<UserOption>, { context }: Context) => ReactNode' is not assignable to type '(data: unknown, formatOptionLabelMeta: FormatOptionLabelMeta<unknown>) => ReactNode'.
Types of parameters 'data' and 'data' are incompatible.
Type 'unknown' is not assignable to type 'Partial<UserOption>'
*/
formatOptionLabel={formatOptionLabel}
/>
) I feel like I've defined |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I noticed you're using a component called |
Beta Was this translation helpful? Give feedback.
I noticed you're using a component called
Search
? How is that defined? Most likely theSearch
component is not correctly forwarding the generics fromSelect
toSearch
. See the section on "Wrapping the Select component" in the TypeScript guide for more details.