A <Select.Item /> must have a value prop that is not an empty string #2421
Replies: 3 comments 3 replies
-
Same here, the current design disallows empty strings at runtime but allows them at compile-time in TypeScript, creating a mismatch and undermining type safety. The lack of compile-time errors for what becomes a runtime issue is problematic and counterintuitive. There is no reasonable way to determine a string that is not empty, so the type you currently defined as string is correct IMO. If there were compile-time errors I believe this would be an okay change, but allowing a dev to make a mistake they may only realise during run-time is the reason many adopted TypeScript in order to avoid. |
Beta Was this translation helpful? Give feedback.
-
I also am struggling with making a generic select component for my project's filters. I propose to allow a select item with an empty string. The placeholder can still be displayed if this item is selected, no? Even the HTML Standard is giving an item with an empty value as an example to have a placeholder: |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I am using a
<Select>
component with shadcn/ui. In version 1.x.x I could create a select item with an empty string value to allow user the option to unselect. However since version 2.0.0, it throw an error whenever I pass an empty value and complain that the key is duplicated if no value is pass.Beta Was this translation helpful? Give feedback.
All reactions