react-range
react-range copied to clipboard
Expose RangeProps
It would be really helpful if the typings for Range props are exposed. Happy to open a PR.
Thanks for making this!
Sounds good
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.
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
You can simplify the type:
type ThumbProps = Parameters<React.ComponentProps<typeof Range>['renderThumb']>[0];
type TrackProps = Parameters<React.ComponentProps<typeof Range>['renderTrack']>[0];