2

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.

Chris
  • 35
  • 1
  • 3

1 Answers1

1

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.

Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357
  • Yes RangeValue can be imported is this okay if it is imported this deep. import { RangeValue } from '../../../../node_modules/rc-picker/lib/interface'; – Chris Oct 13 '20 at 08:40
  • 2
    @Chris hm ..it's not great .. see if maybe there is another suggestion, sometimes there may be more than one, and the first is not necessarily the best. It's a type.. so this import will not make it into your runtime code .. still rather ugly but id still use it as it is the actual required type. Maybe `rc-picker/lib/interface` also works ? – Titian Cernicova-Dragomir Oct 13 '20 at 08:46
  • 1
    Yeah it works! the reason I imported that way because I don't get any intellisense, thinking that it may not work but it's okay now. thank you for your time. – Chris Oct 13 '20 at 08:50
  • 1
    @Chris did you find a better alternative or a way to properly do this istead of going all the way and importing it from node_modules? – tHeSiD Jan 04 '21 at 14:10
  • @tHeSiD rc-picker/lib/interface – Chris Apr 30 '21 at 11:10