Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the date typing for ReactDatePickerProps in EuiDatePicker Typescript #3319

Closed
TAYTS opened this issue Apr 15, 2020 · 1 comment · Fixed by #3343
Closed

Unify the date typing for ReactDatePickerProps in EuiDatePicker Typescript #3319

TAYTS opened this issue Apr 15, 2020 · 1 comment · Fixed by #3343
Assignees

Comments

@TAYTS
Copy link
Contributor

TAYTS commented Apr 15, 2020

Is it possible to add null to the ReactDatePickerProps startDate props as Typescript complaint about tying between the moment.Moment | null and moment.Moment | undefined?

I faced this issue when trying to use useState hook:

const [startDate, setStartDate] = useState<moment.Moment | null>(moment());

<EuiDatePickerRange
    startDateControl={
        <EuiDatePicker
            selected={startDate}
            onChange={(date) => setStartDate(date)}
            startDate={startDate as moment.Moment | undefined}
            aria-label="Start date"
         />
    }
    endDateControl={<EuiDatePicker />}
/>

Although the issue can simply resolved by just casting to moment.Moment | undefined but I think it might be nicer to unify the typing since most of the date has the moment.Moment | null type.

Below are the code reference:

onChange?(
date: moment.Moment | null,
event?: React.SyntheticEvent<any>
): void;

selected?: moment.Moment | null;

startDate?: moment.Moment;

@chandlerprall chandlerprall self-assigned this Apr 17, 2020
@chandlerprall
Copy link
Contributor

Makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants