slider icon indicating copy to clipboard operation
slider copied to clipboard

"Module '"rc-slider"' has no exported member 'Range'."

Open alicerocheman opened this issue 2 years ago • 13 comments

import { Range } from 'rc-slider'; => error: "Module '"rc-slider"' has no exported member 'Range'."

after upgrading to "rc-slider": "^10.0.0-alpha.6"

doc still says you can import Range from rc-slider.

forced to rollback.

alicerocheman avatar Mar 25 '22 08:03 alicerocheman

I am using version > "rc-slider": "^10.0.0-alpha.6"

I think the documentation has not been updated. To use the range feature in version "^10.0.0-alpha.6"

You have to do this >

  1. Import rc-slider like that > image

  2. To use the range functionality just add range to the slider component image

Ashvin-Pal avatar Mar 31 '22 10:03 Ashvin-Pal

This seems to work, however now the onChange type is number | number[] instead of number[] which it should always be for a range slider. Is there a way to tell typescript that the value of onChange will be of type number? I see in the index.d.ts type that SliderProps has a generic called ValueType, but I'm not suer how to pass that from JSX.

TimoWestland avatar Apr 22 '22 13:04 TimoWestland

value, defaultValue, onChange, onBeforeChange, onAfterChange are all using ValueType = number | number[] which is incorrect. The type of ValueType should be depending on the value of the range prop.

Something like: range extends true ? number[] : number

fvoordeckers avatar Apr 27 '22 07:04 fvoordeckers

Same for all the range-only properties, which are now optional. These properties should be undefined in the case range is not true and optional (or not) when it is a range selector. Otherwise the typings allow setting range specific properties on a simple slider.

fvoordeckers avatar Apr 27 '22 07:04 fvoordeckers

onChange still has error. Any idea on how to type it?

Type 'Dispatch<SetStateAction<number[]>>' is not assignable to type '(value: number | number[]) => void'. Types of parameters 'value' and 'value' are incompatible. Type 'number | number[]' is not assignable to type 'SetStateAction<number[]>'. Type 'number' is not assignable to type 'SetStateAction<number[]>'.ts(2322)

hilo2120 avatar Apr 30 '22 16:04 hilo2120

I solved it on my side by just casting the type

const handleChange = (_input: number | number[]) => {
    /* if you're using range */
    const input = _input as number[] 

    /* if you're only using the slider  */
    const input = _input as number
}

Ashvin-Pal avatar May 01 '22 12:05 Ashvin-Pal

onChange still has error. Any idea on how to type it?

Type 'Dispatch<SetStateAction<number[]>>' is not assignable to type '(value: number | number[]) => void'. Types of parameters 'value' and 'value' are incompatible. Type 'number | number[]' is not assignable to type 'SetStateAction<number[]>'. Type 'number' is not assignable to type 'SetStateAction<number[]>'.ts(2322)

@hilo2120 Looks like you are passing the state set action as an onchange event handler. You need to write a handleChange function that will call the state setter.

I solved it on my side by just casting the type

const handleChange = (_input: number | number[]) => {
    /* if you're using range */
    const input = _input as number[] 

    /* if you're only using the slider  */
    const input = _input as number
}

@Ashvin-Pal would make Typescript useless because we're still guessing the type. You could also check if the input is an Array and depend your typings on that result. But both are workarounds and should be fixed by a change in the typings based on the range param.

fvoordeckers avatar May 05 '22 08:05 fvoordeckers

@fvoordeckers yeap I had no choice but to use a workaround for now.

Ashvin-Pal avatar May 05 '22 13:05 Ashvin-Pal

@Ashvin-Pal or someone else. Hello, I can't figure how to display the tooltip in version 10. Any idea ?

guillaumeBOSSIS avatar May 23 '22 13:05 guillaumeBOSSIS

@Ashvin-Pal or someone else. Hello, I can't figure how to display the tooltip in version 10. Any idea ?

You can check out the example over here > https://codesandbox.io/s/lzsr20?file=/App.tsx

Ashvin-Pal avatar May 26 '22 14:05 Ashvin-Pal

Thanks, I finally went down to the previous version as it was kind of urgent. And finally it seems easier with the previous version !

guillaumeBOSSIS avatar May 31 '22 09:05 guillaumeBOSSIS

@Ashvin-Pal Hi, I am having trouble with getting the tooltips working in v 10 using typescript. I found you example which seems like it would have fixed the issue, but it's currently not working and complaining about tipprops? Any idea what would be needed to get it working again?

CBurrows87 avatar Jul 12 '22 11:07 CBurrows87

Attempted to upgrade but hit the same snag, agreed changing ValueType to something like fvoordeckers said would resolve the issue:

range extends true ? number[] : number

schemata-issimo avatar Sep 17 '22 05:09 schemata-issimo

better use npm i [email protected]

Shamimrahman avatar Sep 29 '22 11:09 Shamimrahman

You must do imports like this

import Slider from "rc-slider"; const createSliderWithTooltip = Slider.createSliderWithTooltip; const Range = createSliderWithTooltip(Slider.Range);

After that Range can accept the props.

dotjsNet avatar Nov 23 '22 07:11 dotjsNet

I tried this with the latest version (10.1.0) and this does not seem to work:

image

Property 'createSliderWithTooltip' does not exist on type 'ForwardRefExoticComponent<SliderProps<number | number[]> & RefAttributes<SliderRef>>'.ts(2339)

Property 'Range' does not exist on type 'ForwardRefExoticComponent<SliderProps<number | number[]> & RefAttributes<SliderRef>>'.ts(2339)

Searching for createSliderWithTooltip (https://github.com/react-component/slider/search?q=createSliderWithTooltip) results in two hits in code, both are commented out.

wwwouter avatar Nov 24 '22 12:11 wwwouter

I tried this with the latest version (10.1.0) and this does not seem to work:

image

Property 'createSliderWithTooltip' does not exist on type 'ForwardRefExoticComponent<SliderProps<number | number[]> & RefAttributes<SliderRef>>'.ts(2339)

Property 'Range' does not exist on type 'ForwardRefExoticComponent<SliderProps<number | number[]> & RefAttributes<SliderRef>>'.ts(2339)

Searching for createSliderWithTooltip (https://github.com/react-component/slider/search?q=createSliderWithTooltip) results in two hits in code, both are commented out.

Check out this demo with source code http://react-component.github.io/slider/?path=/story/rc-slider--handle

dotjsNet avatar Nov 24 '22 14:11 dotjsNet

@dotjsNet Have you tried this outside of the https://github.com/react-component/slider repository with the latest version of rc-slider?

If I ignore the typing by casting Slider to any and log createSliderWithTooltip, I get undefined back.

import Slider from 'rc-slider';
const { createSliderWithTooltip } = Slider as any;
console.log('createSliderWithTooltip', createSliderWithTooltip);
image

I suspect the code on http://react-component.github.io/slider/?path=/story/rc-slider--handle runs <v10.

Here is the commit that removes createSliderWithTooltip https://github.com/react-component/slider/commit/c33764e4e74d5b45cf4f17df321035b821a4161b

wwwouter avatar Nov 25 '22 07:11 wwwouter

so a new non-beta major release introduced breaking changes and yet the documentation has not been updated, and it looks like the vast majority of PRs merged in this repo are not even reviewed. i'm sorry but this screams "shitty library". i'm out.

szamanr avatar Dec 08 '22 10:12 szamanr

EDIT: PR Approved, Thanks !

PR made https://github.com/react-component/slider/pull/867

code2be avatar Apr 15 '23 03:04 code2be

@szamanr - have you found a decent alternative range slider?

princefishthrower avatar Apr 20 '23 07:04 princefishthrower

@szamanr - have you found a decent alternative range slider?

@princefishthrower no, i've pinned the dependency to 9.2.4. i left a note to look into react-compound-slider in the future.

szamanr avatar Apr 20 '23 07:04 szamanr

Found yet another slider component: https://github.com/n3r4zzurr0/react-range-slider-input but this one doesn't have types. Just found this nice blog post, at this point I'll accept a completely custom one, tired of searching for a library for such simple functionality: https://benhoneywill.com/building-a-range-slider-component-in-react/

princefishthrower avatar Apr 20 '23 07:04 princefishthrower

it seems that the examples are updated to the new version see /demo/handle just the README and changelog is outdated

alissaVrk avatar May 06 '23 08:05 alissaVrk

@TimoWestland about onChange type the SliderProps is generic you can pass the value type. for range it will be SliderProps<number[]>

though there is a bug there.. since the Slider itself isn't generic

alissaVrk avatar May 06 '23 08:05 alissaVrk