react-range icon indicating copy to clipboard operation
react-range copied to clipboard

Expose RangeProps

Open glennreyes opened this issue 5 years ago • 3 comments

It would be really helpful if the typings for Range props are exposed. Happy to open a PR.

Thanks for making this!

glennreyes avatar Dec 10 '20 15:12 glennreyes

Sounds good

tajo avatar Dec 10 '20 19:12 tajo

That would be very helpful if we want to move renderTrack callback definition to another file.

I see these types are defined, but it seems like they are not exported.

image image

Workaround we can use, before all types are exported:

// index.ts
import { Range } from 'react-range';

type GenericOf<T> = T extends React.Component<infer X> ? X : never;

type GetRangePropType<PropName extends keyof GenericOf<Range>> = GenericOf<Range>[PropName];

type RenderTrackFunctionType = GetRangePropType<'renderTrack'>; // (params: IRenderTrackParams) => React.ReactNode

type IRenderTrackParams = Parameters<RenderTrackFunctionType>[0]; // IRenderTrackParams

ffilipovicc98 avatar Jun 08 '22 12:06 ffilipovicc98

You can simplify the type:

type ThumbProps = Parameters<React.ComponentProps<typeof Range>['renderThumb']>[0];
type TrackProps = Parameters<React.ComponentProps<typeof Range>['renderTrack']>[0];

gilbarbara avatar Dec 15 '22 12:12 gilbarbara