Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
8.1k stars 2.24k forks source link

[BUG] selectMultiples types causing typescript error #4999

Open fzn0x opened 3 months ago

fzn0x commented 3 months ago
Type '{ selected: Date; onChange: (date: [Date, Date]) => void; portalId: string; locale: string; showTimeSelect: true; timeFormat: string; timeIntervals: number; dateFormat: string; customInput: Element; }' is not assignable to type 'IntrinsicAttributes & (IntrinsicClassAttributes<DatePicker> & ((Pick<Readonly<Omit<CalendarProps, "dropdownMode" | ... 19 more ... | "outsideClickIgnoreClass"> & ... 5 more ... & { ...; }>, "date" | ... 107 more ... | "onChangeRaw"> & InexactPartial<...> & InexactPartial<...>) | (Pick<...> & ... 1 more ... & Inexact...'.
  Property 'selectsMultiple' is missing in type '{ selected: Date; onChange: (date: [Date, Date]) => void; portalId: string; locale: string; showTimeSelect: true; timeFormat: string; timeIntervals: number; dateFormat: string; customInput: Element; }' but required in type 'Pick<Readonly<Omit<CalendarProps, "dropdownMode" | "onSelect" | "setOpen" | "dateFormat" | "preSelection" | "setPreSelection" | "selectsRange" | "handleOnKeyDown" | ... 12 more ... | "outsideClickIgnoreClass"> & ... 5 more ... & { ...; }>, "date" | ... 107 more ... | "onChangeRaw">'.ts(2322)
index.d.ts(94, 5): 'selectsMultiple' is declared here.
<DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      portalId="root-portal"
      locale="pt-BR"
      showTimeSelect
      timeFormat="p"
      timeIntervals={15}
      dateFormat="Pp"
      customInput={<InputDate />}
    />

Screenshot 2024-07-22 191218

Svish commented 3 months ago

I got this too, and think I fixed it by being explicit in the onChange callback: onChange={(date: Date | null) => setStartDate(date)}

RammasEchor commented 2 months ago

Same error here. onChange={(date: Date | null) => setStartDate(date)} works, but I would prefer not to have my variables declared as date: Date | null. I got this: onChange={(date: Date | null) => date ? setStartDate(date) : null}