Typescript Error using react-daterange-picker "No overload matches this call."

When I try to use react-daterange-picker in my React Typescript app, I get the error

No overload matches this call.
  Overload 1 of 2, '(props: RangeProps<DateRangePicker> | SingleProps<DateRangePicker> | Readonly<RangeProps<DateRangePicker>> | Readonly<...>): DateRangePicker', gave the following error.
    Type 'Date[]' is not assignable to type 'Moment | (MomentRange & typeof import("/Users/nyxynyx/test/node_modules/moment/ts3.1-typings/moment.d.ts")) | DateRange | undefined'.
      Type 'Date[]' is missing the following properties from type 'Moment': format, startOf, endOf, add, and 80 more.
  Overload 2 of 2, '(props: Props<DateRangePicker>, context: any): DateRangePicker', gave the following error.
    Type 'Date[]' is not assignable to type 'Moment | (MomentRange & typeof import("/Users/nyxynyx/test/node_modules/moment/ts3.1-typings/moment.d.ts")) | DateRange | undefined'.
      Type 'Date[]' is not assignable to type 'Moment'.  TS2769

    20 |         <DateRangePicker 
    21 |             onChange={onChange}
  > 22 |             value={value}
       |             ^
    23 |         />
    24 |     )
    25 | }

My code is based on the official example in the package repo.

Why is there a Typescript error here, and how can we fix it?

React Typescript code:

import React, { useState } from 'react';
import DateRangePicker from 'react-daterange-picker';

export function Foo(): JSX.Element {

    const [ value, onChange ] = useState([new Date(), new Date()]);

    return (
        <DateRangePicker 
            onChange={onChange}
            value={value}
        />
    )
}

85 thoughts on “Typescript Error using react-daterange-picker "No overload matches this call."”

  1. 509083 105608I dont normally take a look at these kinds of sites (Im a pretty shy person) – but even though I was a bit shocked as I was reading, I was undoubtedly a bit excited as nicely. Thanks for giving me a big smile for the day 487841

    Reply
  2. i need a direct payday loan lender, i need loan money. i need a loan now direct lender need loan i own my home outright and need a loan i need a direct loan lender, cash for payday loans, cash advances, cash advance online, payday advance loans without bank account. Business describes business, internationally active.

    Reply

Leave a Comment