-
-
Notifications
You must be signed in to change notification settings - Fork 279
Closed
Labels
component: sliderChanges related to the slider component.Changes related to the slider component.type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.typescript
Description
Feature request
Summary
The Slider accepts values of type Array<number> | number but the onValueChange and onValueCommitted callbacks don't narrow the type of the value parameter to number or Array<number> and users need to type cast it manually.
Example of code throwing a TS error:
// ❌ Argument of type 'number | number[]' is not assignable to parameter of type 'SetStateAction<number>'.
// Type 'number[]' is not assignable to type 'SetStateAction<number>'.
const [value, setValue] = React.useState(25);
<Slider.Root value={value} onValueChange={(value) => setValue(value}>Example of type casting needed to overcome the TS error:
const [value, setValue] = React.useState(25);
<Slider.Root value={value} onValueChange={(value) => setValue(value as number}>Motivation
Avoid users needing to do manual type casting.
Metadata
Metadata
Assignees
Labels
component: sliderChanges related to the slider component.Changes related to the slider component.type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.typescript
Projects
Status
Recently completed