Skip to content

Cannot use DatePicker as JSX ElementΒ #3784

@RonnyLark

Description

@RonnyLark

Describe the bug
Using DatePicker with TS strict mode throws the following type error:

'DatePicker' cannot be used as a JSX component.
  Its instance type 'ReactDatePicker<never, undefined>' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'import("/Users/ronny.efronny/projects/frontend/node_modules/@types/react-dom/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
        Type '{}' is not assignable to type 'ReactNode'.ts(2786)

To Reproduce

  1. Enable TS strict mode, or at least the rule strictFunctionTypes.
  2. Use DatePicker.

Expected behavior
No errors.

Screenshots
image

  • OS: Mac OS Monterey (12.6).
  • TS version 4.9.0
  • react-datepicker version 4.8.0
  • @types/react-datepicker version 4.4.2

This is currently preventing me from enabling strict mode on my project, and I would like to refraing from using ts-ignore. What can be done?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions