arqex / react-datetime

A lightweight but complete datetime picker react component.
1.99k stars 872 forks source link

`currentView` missing from `DatetimepickerState` in TS `typings/DateTime.d.ts` #826

Open rembrandtreyes opened 2 years ago

rembrandtreyes commented 2 years ago

I'm Submitting a ...

[x] Bug report
[ ] Feature request
[ ] Support request

I am currently using the TypeScript types from the Datetime component and noticed when I try to access the state.currentView I get this TS error Argument of type '{ currentView: string; }' is not assignable to parameter of type 'DatetimepickerState | ((prevState: Readonly<DatetimepickerState>, props: Readonly<DatetimepickerProps>) => DatetimepickerState | ... 1 more ... | null) | Pick<...> | null'.

Looking at the code looks like you have

this.state = {
  open: !props.input,
  currentView: props.initialViewMode || this.getInitialView(),
  viewDate: this.getInitialViewDate(selectedDate),
  selectedDate:
    selectedDate && selectedDate.isValid() ? selectedDate : undefined,
  inputValue: this.getInitialInputValue(selectedDate),
};

And in DateTime.d.ts you have

export interface DatetimepickerState {
  updateOn: string;
  inputFormat: string;
  viewDate: Moment;
  selectedDate: Moment;
  inputValue: string;
  open: boolean;
}

Shouldn't DatetimepickerState include currentView: ViewMode in the interface and it seems like you can remove updateOn: string;?