Hacker0x01 / react-datepicker

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

Type '{ label: string; elected: Date; onChange: (date: Date) => void; }' is missing the following properties ts(2322) in version 7.2 #4945

Closed Ofer-Gal closed 1 day ago

Ofer-Gal commented 2 days ago

Describe the bug TypeScript complains about optional properties in VSCode.

To Reproduce <DatePicker label="Select Start Date/Time (Optional) " elected={startDate} onChange={handleChange} /> Causes TS error: Type '{ label: string; elected: Date; onChange: (date: Date) => void; }' is not assignable to type 'IntrinsicAttributes & (IntrinsicClassAttributes<DatePicker> & (Readonly<DatePickerProps> & Readonly<...>))'. Type '{ label: string; elected: Date; onChange: (date: Date) => void; }' is missing the following properties from type 'Readonly<Omit<React.ComponentPropsWithoutRef<typeof Calendar>, "setOpen" | "dateFormat" | "preSelection" | "onSelect" | "onClickOutside" | "highlightDates" | "holidays" | "shouldFocusDayInline" | "outsideClickIgnoreClass" | ... 11 more ... | "dropdownMode"> & ... 5 more ... & { ...; }>': excludeScrollbar, icon, onSelect, selectsMultiple ts(2322) Expected behavior A clear and concise description of what you expected to happen. When I use older version, it does not complain. Where the error in new version reaten in TS

Screenshots

image

Desktop (please complete the following information):

Is there esLint override I can use?

Thank you

yuki0410-dev commented 1 day ago

@Ofer-Gal I was able to reproduce it with codesandbox. https://codesandbox.io/p/sandbox/react-datepicker-4945-zkv4ns?file=%2Fsrc%2FApp.tsx%3A14%2C54

Since there are no label props in DatePicker, please remove them or use the appropriate props. https://github.com/Hacker0x01/react-datepicker/blob/main/docs/datepicker.md

Ofer-Gal commented 1 day ago

Thanks