react-multi-date-picker icon indicating copy to clipboard operation
react-multi-date-picker copied to clipboard

Typescript support in onChange method for datepicker

Open PCPbiscuit opened this issue 3 years ago • 0 comments

I'm using DatePicker in my typescript react project and facing an issue regarding onChange method. It returns DateObject so in order to do something with it we have to format/parse it. So I'm using .unix method but Typescript says Property 'unix' does not exist on type 'DateObject | DateObject[]'. Property 'unix' does not exist on type 'DateObject[]'.ts(2339) my DatePicker component:

Datepicker props

type Props = {
  onChange?(selectedDates: DateObject | DateObject[] | null): void;
  value: DateObject | DateObject[] | Date | string[] | null | string | number;
  format?: string;
};
<DatePicker
     value={value}
     onChange={(dates)=>(onChange(dates.unix))}
     format={format}
   />

May be my approach is wrong so don't hesitate to point it out

PCPbiscuit avatar Mar 16 '22 14:03 PCPbiscuit