sghall / react-compound-slider

:black_medium_small_square: React Compound Slider | A small React slider with no opinion on markup or styles
https://react-compound-slider.netlify.com
MIT License
626 stars 80 forks source link

Readonly Error #108

Closed earllapura closed 4 years ago

earllapura commented 4 years ago

https://github.com/sghall/react-compound-slider/blob/f3ea10e62671ee91b0d2719d73f1d250813457b4/docs/src/demos/horizontal/Example2.tsx#L24

I tried to use the example for my project using the library with version 2.4, React v16.11 and Typescript 3.7.2. However, I get the error as seen below

No overload matches this call.
  Overload 1 of 2, '(props: SliderProps, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | Component<...> | null', gave the following error.
    Type '(value: number[]) => void' is not assignable to type '(values: readonly number[]) => void'.
      Types of parameters 'value' and 'values' are incompatible.
        The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.
  Overload 2 of 2, '(props: PropsWithChildren<SliderProps>, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | Component<...> | null', gave the following error.
    Type '(value: number[]) => void' is not assignable to type '(values: readonly number[]) => void'.

Shouldn't the parameter be ReadonlyArray<number>?

sghall commented 4 years ago

Hey, there. I see what the issue is. I updated master to Typescript and I'm still working on it (master is what's in the beta version). You are using the library version 2.4 which was in JS. So you're kind of caught up in this transition period.

However, good point on the readonly. I should update that. This was the original discussion around that https://github.com/sghall/react-compound-slider/pull/21.

sghall commented 4 years ago

Ok. I just published a new beta version of 3.0 (3.0.0-beta.1) and updated the master branch with all the arrays as ReadonlyArray<number>. So the demos should work if you take them off master.

I updated this TS sandbox to confirm it works with readonly values passed in: https://codesandbox.io/s/6zpjmw1x3w

If anyone wants to install the beta (npm install react-compound-slider@beta) and provide any feedback, please feel free. Hoping to get everything done over the next couple of weeks.

Thanks for raising the issue.

earllapura commented 4 years ago

@sghall Thanks for the tip!