Closed nik-webdevelop closed 1 year ago
@nik-webdevelop If the Select
component has problems inferring the option type from the given options, you can provide a set type for those options to the component:
<Select<{name: string, value: string}>
options={colors}
getOptionLabel={(opt) => opt.name} // properly inferred as option
/>
Thanks for your response. Yes, this will work, but it's not really handy to explicitly pass option type each time. I am just surprised that an option isn't inferring by default.
P.S. also setting defaultValue
or value
fixes an option inferring
When I use Select with groups, the option parameter in getOptionalLabel/getOptionalValue is inferred as a whole group. Function
getOptionLabel={(option) => option.name}
is accessing the name properly but TS shows errors.Codesandbox