palantir / blueprint

A React-based UI toolkit for the web
https://blueprintjs.com/
Apache License 2.0
20.73k stars 2.18k forks source link

Docs for DateRange show the wrong type (null should be undefined) #3838

Closed elilambnz closed 4 years ago

elilambnz commented 4 years ago

Environment

If possible, link to a minimal repro (fork this code sandbox): https://codesandbox.io/s/blueprint-sandbox-wrskg

Type 'null[]' is missing the following properties from type '[Date | undefined, Date | undefined]': 0, 1ts(2739)
dateRangePicker.d.ts(75, 5): The expected type comes from property 'value' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<DateRangePicker> & Pick<Readonly<IDateRangePickerProps> & Readonly<{ children?: ReactNode; }>, "children"> & Partial<Pick<...>> & Partial<...>'
adidahiya commented 4 years ago

The error message tells you which types are supported; you may use undefined, but not null. Is there a particular reason you need to use null for the start and end?

elilambnz commented 4 years ago

There's no particular reason I need to use null, this is simply a result of following the documentation of the DateRangePicker component. It's also used in the code example.

After a quick look at the source code, I initially thought that if I changed it to undefined that it would break the non-null checks. But of course != null is still falsey for undefined. Thanks JavaScript!

Nonetheless, this still causes type errors if following exactly how the documentation does it.

adidahiya commented 4 years ago

Hmm sorry about that, it looks like the documentation at https://blueprintjs.com/docs/#datetime/daterangepicker.date-ranges is wrong... it should use undefined instead of null. Should be an easy PR to fix this!

As for the code example... null is actually used in the component state of DateRangePickerExample, but it is never sent to DateRangePicker itself since the example uses the component in an "uncontrolled" manner... yeah I understand that's a bit confusing, perhaps it's worth a small refactor.