Chris
Chris

Reputation: 35

Type definition of RangePicker onChange date paramater

As per documentation ant design 4.7

onChange    Callback function, can be executed when the selected time is changing   function(dates: [moment, moment], dateStrings: [string, string])

Error

Type '(date: Array<Moment>, dateString: Array<string>) => void' is not assignable to type '(values: RangeValue<Moment>, formatString: [string, string]) => void'.
  Types of parameters 'date' and 'values' are incompatible.
    Type 'RangeValue<Moment>' is not assignable to type 'Moment[]'.
      Type 'null' is not assignable to type 'Moment[]'.

Code

  const dateTimeOnChange = (
    date: Array<Moment>,
    dateString: Array<string>
  ): void => {
    console.log(date);
    console.log(dateString);
  };

Can't find type definition for and design RangePicker onChange 1st parameter type.

Upvotes: 2

Views: 4515

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249786

From the error message and the docs the problem is pretty clear. The parameters are not arbitrary length arrays, but rather fixed size arrays (aka tuples), also the date parameter may be null

Try

const dateTimeOnChange = (
    date: [Moment, Moment] | null,
    dateString: [string, string]
  ): void => {
    console.log(date);
    console.log(dateString);
  };

You could probably also use date: RangeValue<Moment> if RangeValue is exported from the module it is declared in.

Upvotes: 1

Related Questions