react-day-picker icon indicating copy to clipboard operation
react-day-picker copied to clipboard

types: investigate type error with mode prop

Open gpbl opened this issue 3 years ago • 0 comments

  Hi! I'm not opening new issue because I think it can be somehow related with this one 🙂 

So, after updating to 8.3.1 this issue appeared: Screenshot 2022-10-05 at 12 00 00

mode and selectedDate comes from props. Their types are defined as follows:

mode?: 'single' | 'multiple' | 'range';
selectedDate: DatesType

(and DatesType: Date | Date[] | DateRange | undefined, where DateRange is imported from `react-day-picker)

At this point I ran out of ideas how to resolve this issue. The only solution that worked, was something like this:

{ mode === 'single' && <DayPicker mode='single' selected={selectedDate as Date | undefined} {...otherProps} /> }
{ mode === 'multiple' && <DayPicker mode='multiple' selected={selectedDate as Date[] | undefined} {...otherProps} /> }
{ mode === 'range' && <DayPicker mode='range' selected={selectedDate as DateRange | undefined} {...otherProps} /> }

but to be hones it doesn't look too clean.

Maybe you would know what is the issue here and if there is a better way to resolve it than the one I showed above?

Thanks in advance 😃

Originally posted by @bartlomiej-bykowy in https://github.com/gpbl/react-day-picker/discussions/1570#discussioncomment-3803763

gpbl avatar Oct 12 '22 16:10 gpbl