Skip to content

OnChange typescript types do not allow to have simple datepicker and range datepicker  #3050

@DenysPavlenko

Description

@DenysPavlenko

Describe the bug
I am using typescript in my project and I am trying to create a reusable DatePicker component with ability to display range datepicker or simple datepicker (with one date) depend on passing such props as selectsRange, startDate, endDate. But typescript doesn't allow me to do that, it throws such errors:

  1. Type 'Date' is not assignable to type '[Date, Date]' for the range variant
  2. Type '[Date, Date]' is not assignable to type Date for a simple datepicker

To Reproduce
Try to set such type check for the datepicker wrapper component: onChange: (date: Date | [Date, Date] | null, event: React.SyntheticEvent) => void, and then use onChange on the instance component.

Expected behavior
It should allow conditionally create 2 variants of datepicker (it is possible with clean jsx)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions